﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
namespace TCCT_CTC_CSDLDangVienV1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private bool CheckExitsCB(string khoa)
        {
            List<SqlParameter> arrParameters = new List<SqlParameter>();
            arrParameters.Add(SqlHelper.CreateParameterObject("@Khoa", SqlDbType.NVarChar, ParameterDirection.Input, khoa));

            DataTable temdt = SqlHelper.ExecuteDataTable(CommandType.Text, "Select * from tblCanBo where khoa=@khoa", arrParameters);
            if (temdt.Rows.Count > 0)
                return true;

            return false;
        }

        private void btnChuyenDoi_Click(object sender, EventArgs e)
        {

            try
            {
                // chỉnh sửa cho phù hợp với mỗi lần convert
                SqlHelper_Convert.ConnectDatabase(txtServer.Text.Trim(), txtUser.Text.Trim(), txtPass.Text.Trim(), txtDatabase.Text.Trim());

                string sqlInsertTuDien = "Insert Into tblTuDien(Deleted, TuDienID, DauMoiID, ParentID, TenGoi, MaDanhMuc, CapTren, UserID, CreateDate) Values(@Deleted, @TuDienID, @DauMoiID, @ParentID, @TenGoi, @MaDanhMuc, @CapTren, @UserID, GetDate());";
                List<SqlParameter> arrParameters = new List<SqlParameter>();
                DataTable dtTuDien = new DataTable();
                string TuDien = "", MaDM = "";
                Nullable<int> parentID = null;
                string captren = "";
                string maTem = "";


                #region chuyen doi tu dien Benh
                TuDien = "Benh";
                MaDM = MyConst.TD.Benh.Ma;
                dtTuDien = SqlHelper_Convert.ExecuteDataTable(CommandType.Text, "Select * From " + TuDien);
                foreach (DataRow dr in dtTuDien.Rows)
                {
                    lblTrangThai.Text = "Đang cập nhật từ điển " + TuDien + ": " + dr["Ma"].ToString();

                    Application.DoEvents();

                    arrParameters.Clear();

                    arrParameters.Add(SqlHelper.CreateParameterObject("@Deleted", SqlDbType.Bit, ParameterDirection.Input, dr["An_Hien"]));
                    arrParameters.Add(SqlHelper.CreateParameterObject("@TuDienID", SqlDbType.Int, ParameterDirection.Input, dr["ID"].ToString()));
                    arrParameters.Add(SqlHelper.CreateParameterObject("@DauMoiID", SqlDbType.Int, ParameterDirection.Input, MyCommon.CurrentUserDauMoiID));
                    parentID = null;
                    if (dr["Ma"].ToString().Length > 3)
                    {
                        try
                        {
                            parentID = Util.ToInt(SqlHelper_Convert.ExecuteScalar(CommandType.Text, "Select ID From " + TuDien + " Where Ma='" + dr["Ma"].ToString().Substring(0, dr["Ma"].ToString().Length - 3) + "'"));
                        }
                        catch
                        {

                        }
                    }
                    arrParameters.Add(SqlHelper.CreateParameterObject("@ParentID", SqlDbType.Int, ParameterDirection.Input, parentID));

                    arrParameters.Add(SqlHelper.CreateParameterObject("@TenGoi", SqlDbType.NVarChar, ParameterDirection.Input, Converter.TCVN3ToUnicode(dr["Ten"].ToString())));
                    arrParameters.Add(SqlHelper.CreateParameterObject("@MaDanhMuc", SqlDbType.NVarChar, ParameterDirection.Input, MaDM));
                    captren = "";
                    maTem = dr["Ma"].ToString();

                    while (maTem != "")
                    {
                        try
                        {
                            captren = SqlHelper_Convert.ExecuteScalar(CommandType.Text, "Select ID From " + TuDien + " Where Ma='" + maTem + "'").ToString() + ";" + captren;
                            maTem = maTem.Substring(0, maTem.Length - 3);
                        }
                        catch
                        {
                            break;
                        }
                    }
                    captren = ";" + captren;

                    arrParameters.Add(SqlHelper.CreateParameterObject("@CapTren", SqlDbType.NVarChar, ParameterDirection.Input, captren));
                    arrParameters.Add(SqlHelper.CreateParameterObject("@UserID", SqlDbType.Int, ParameterDirection.Input, MyCommon.CurrentUserID));
                    SqlHelper.ExecuteNonQuery(CommandType.Text, sqlInsertTuDien, arrParameters);
                }

                #endregion chuyen doi tu dien Benh

                #region chuyen doi tu dien BinhC
                TuDien = "BinhC";
                MaDM = MyConst.TD.BinhC.Ma;
                dtTuDien = SqlHelper_Convert.ExecuteDataTable(CommandType.Text, "Select * From " + TuDien);
                foreach (DataRow dr in dtTuDien.Rows)
                {
                    lblTrangThai.Text = "Đang cập nhật từ điển " + TuDien + ": " + dr["Ma"].ToString();

                    Application.DoEvents();

                    arrParameters.Clear();
                    arrParameters.Add(SqlHelper.CreateParameterObject("@Deleted", SqlDbType.Bit, ParameterDirection.Input, dr["An_Hien"]));
                    arrParameters.Add(SqlHelper.CreateParameterObject("@TuDienID", SqlDbType.Int, ParameterDirection.Input, dr["ID"].ToString()));
                    arrParameters.Add(SqlHelper.CreateParameterObject("@DauMoiID", SqlDbType.Int, ParameterDirection.Input, MyCommon.CurrentUserDauMoiID));
                    parentID = null;
                    if (dr["Ma"].ToString().Length > 3)
                    {
                        try
                        {
                            parentID = Util.ToInt(SqlHelper_Convert.ExecuteScalar(CommandType.Text, "Select ID From " + TuDien + " Where Ma='" + dr["Ma"].ToString().Substring(0, dr["Ma"].ToString().Length - 3) + "'"));
                        }
                        catch
                        {
                        }
                    }
                    arrParameters.Add(SqlHelper.CreateParameterObject("@ParentID", SqlDbType.Int, ParameterDirection.Input, parentID));

                    arrParameters.Add(SqlHelper.CreateParameterObject("@TenGoi", SqlDbType.NVarChar, ParameterDirection.Input, Converter.TCVN3ToUnicode(dr["Ten"].ToString())));
                    arrParameters.Add(SqlHelper.CreateParameterObject("@MaDanhMuc", SqlDbType.NVarChar, ParameterDirection.Input, MaDM));
                    captren = "";
                    maTem = dr["Ma"].ToString();

                    while (maTem != "")
                    {
                        try
                        {
                            captren = SqlHelper_Convert.ExecuteScalar(CommandType.Text, "Select ID From " + TuDien + " Where Ma='" + maTem + "'").ToString() + ";" + captren;
                            maTem = maTem.Substring(0, maTem.Length - 3);
                        }
                        catch
                        {
                            break;

                        }
                    }
                    captren = ";" + captren;

                    arrParameters.Add(SqlHelper.CreateParameterObject("@CapTren", SqlDbType.NVarChar, ParameterDirection.Input, captren));
                    arrParameters.Add(SqlHelper.CreateParameterObject("@UserID", SqlDbType.Int, ParameterDirection.Input, MyCommon.CurrentUserID));
                    SqlHelper.ExecuteNonQuery(CommandType.Text, sqlInsertTuDien, arrParameters);
                }

                #endregion chuyen doi tu dien BinhC

                #region chuyen doi tu dien BoPhan
                TuDien = "BoPhan";
                MaDM = MyConst.TD.BoPhan.Ma;
                dtTuDien = SqlHelper_Convert.ExecuteDataTable(CommandType.Text, "Select * From " + TuDien);
                foreach (DataRow dr in dtTuDien.Rows)
                {
                    lblTrangThai.Text = "Đang cập nhật từ điển " + TuDien + ": " + dr["Ma"].ToString();

                    Application.DoEvents();

                    arrParameters.Clear();
                    arrParameters.Add(SqlHelper.CreateParameterObject("@Deleted", SqlDbType.Bit, ParameterDirection.Input, dr["An_Hien"]));
                    arrParameters.Add(SqlHelper.CreateParameterObject("@TuDienID", SqlDbType.Int, ParameterDirection.Input, dr["ID"].ToString()));
                    arrParameters.Add(SqlHelper.CreateParameterObject("@DauMoiID", SqlDbType.Int, ParameterDirection.Input, MyCommon.CurrentUserDauMoiID));
                    parentID = null;
                    if (dr["Ma"].ToString().Length > 3)
                    {
                        try
                        {
                            parentID = Util.ToInt(SqlHelper_Convert.ExecuteScalar(CommandType.Text, "Select ID From " + TuDien + " Where Ma='" + dr["Ma"].ToString().Substring(0, dr["Ma"].ToString().Length - 3) + "'"));
                        }
                        catch
                        {
                        }
                    }
                    arrParameters.Add(SqlHelper.CreateParameterObject("@ParentID", SqlDbType.Int, ParameterDirection.Input, parentID));

                    arrParameters.Add(SqlHelper.CreateParameterObject("@TenGoi", SqlDbType.NVarChar, ParameterDirection.Input, Converter.TCVN3ToUnicode(dr["Ten"].ToString())));
                    arrParameters.Add(SqlHelper.CreateParameterObject("@MaDanhMuc", SqlDbType.NVarChar, ParameterDirection.Input, MaDM));
                    captren = "";
                    maTem = dr["Ma"].ToString();

                    while (maTem != "")
                    {
                        try
                        {
                            captren = SqlHelper_Convert.ExecuteScalar(CommandType.Text, "Select ID From " + TuDien + " Where Ma='" + maTem + "'").ToString() + ";" + captren;
                            maTem = maTem.Substring(0, maTem.Length - 3);
                        }
                        catch
                        {
                            break;
                        }
                    }
                    captren = ";" + captren;

                    arrParameters.Add(SqlHelper.CreateParameterObject("@CapTren", SqlDbType.NVarChar, ParameterDirection.Input, captren));
                    arrParameters.Add(SqlHelper.CreateParameterObject("@UserID", SqlDbType.Int, ParameterDirection.Input, MyCommon.CurrentUserID));
                    SqlHelper.ExecuteNonQuery(CommandType.Text, sqlInsertTuDien, arrParameters);
                }

                #endregion chuyen doi tu dien BoPhan


                #region chuyen doi tu dien Cap
                TuDien = "Cap";
                MaDM = MyConst.TD.Cap.Ma;
                dtTuDien = SqlHelper_Convert.ExecuteDataTable(CommandType.Text, "Select * From " + TuDien);
                foreach (DataRow dr in dtTuDien.Rows)
                {
                    lblTrangThai.Text = "Đang cập nhật từ điển " + TuDien + ": " + dr["Ma"].ToString();

                    Application.DoEvents();

                    arrParameters.Clear();
                    arrParameters.Add(SqlHelper.CreateParameterObject("@Deleted", SqlDbType.Bit, ParameterDirection.Input, dr["An_Hien"]));
                    arrParameters.Add(SqlHelper.CreateParameterObject("@TuDienID", SqlDbType.Int, ParameterDirection.Input, dr["ID"].ToString()));
                    arrParameters.Add(SqlHelper.CreateParameterObject("@DauMoiID", SqlDbType.Int, ParameterDirection.Input, MyCommon.CurrentUserDauMoiID));
                    parentID = null;
                    if (dr["Ma"].ToString().Length > 3)
                    {
                        try
                        {
                            parentID = Util.ToInt(SqlHelper_Convert.ExecuteScalar(CommandType.Text, "Select ID From " + TuDien + " Where Ma='" + dr["Ma"].ToString().Substring(0, dr["Ma"].ToString().Length - 3) + "'"));
                        }
                        catch
                        {
                        }
                    }
                    arrParameters.Add(SqlHelper.CreateParameterObject("@ParentID", SqlDbType.Int, ParameterDirection.Input, parentID));

                    arrParameters.Add(SqlHelper.CreateParameterObject("@TenGoi", SqlDbType.NVarChar, ParameterDirection.Input, Converter.TCVN3ToUnicode(dr["Ten"].ToString())));
                    arrParameters.Add(SqlHelper.CreateParameterObject("@MaDanhMuc", SqlDbType.NVarChar, ParameterDirection.Input, MaDM));
                    captren = "";
                    maTem = dr["Ma"].ToString();

                    while (maTem != "")
                    {
                        try
                        {
                            captren = SqlHelper_Convert.ExecuteScalar(CommandType.Text, "Select ID From " + TuDien + " Where Ma='" + maTem + "'").ToString() + ";" + captren;
                            maTem = maTem.Substring(0, maTem.Length - 3);
                        }
                        catch
                        {
                            break;
                        }
                    }
                    captren = ";" + captren;

                    arrParameters.Add(SqlHelper.CreateParameterObject("@CapTren", SqlDbType.NVarChar, ParameterDirection.Input, captren));
                    arrParameters.Add(SqlHelper.CreateParameterObject("@UserID", SqlDbType.Int, ParameterDirection.Input, MyCommon.CurrentUserID));
                    SqlHelper.ExecuteNonQuery(CommandType.Text, sqlInsertTuDien, arrParameters);
                }

                #endregion chuyen doi tu dien Cap


                #region chuyen doi tu dien CapHoc
                TuDien = "CapHoc";
                MaDM = MyConst.TD.CapHoc.Ma;
                dtTuDien = SqlHelper_Convert.ExecuteDataTable(CommandType.Text, "Select * From " + TuDien);
                foreach (DataRow dr in dtTuDien.Rows)
                {
                    lblTrangThai.Text = "Đang cập nhật từ điển " + TuDien + ": " + dr["Ma"].ToString();

                    Application.DoEvents();

                    arrParameters.Clear();
                    arrParameters.Add(SqlHelper.CreateParameterObject("@Deleted", SqlDbType.Bit, ParameterDirection.Input, dr["An_Hien"]));
                    arrParameters.Add(SqlHelper.CreateParameterObject("@TuDienID", SqlDbType.Int, ParameterDirection.Input, dr["ID"].ToString()));
                    arrParameters.Add(SqlHelper.CreateParameterObject("@DauMoiID", SqlDbType.Int, ParameterDirection.Input, MyCommon.CurrentUserDauMoiID));
                    parentID = null;
                    if (dr["Ma"].ToString().Length > 3)
                    {
                        try
                        {
                            parentID = Util.ToInt(SqlHelper_Convert.ExecuteScalar(CommandType.Text, "Select ID From " + TuDien + " Where Ma='" + dr["Ma"].ToString().Substring(0, dr["Ma"].ToString().Length - 3) + "'"));
                        }
                        catch
                        {
                        }
                    }
                    arrParameters.Add(SqlHelper.CreateParameterObject("@ParentID", SqlDbType.Int, ParameterDirection.Input, parentID));

                    arrParameters.Add(SqlHelper.CreateParameterObject("@TenGoi", SqlDbType.NVarChar, ParameterDirection.Input, Converter.TCVN3ToUnicode(dr["Ten"].ToString())));
                    arrParameters.Add(SqlHelper.CreateParameterObject("@MaDanhMuc", SqlDbType.NVarChar, ParameterDirection.Input, MaDM));
                    captren = "";
                    maTem = dr["Ma"].ToString();

                    while (maTem != "")
                    {
                        try
                        {
                            captren = SqlHelper_Convert.ExecuteScalar(CommandType.Text, "Select ID From " + TuDien + " Where Ma='" + maTem + "'").ToString() + ";" + captren;
                            maTem = maTem.Substring(0, maTem.Length - 3);
                        }
                        catch
                        {
                            break;
                        }
                    }
                    captren = ";" + captren;

                    arrParameters.Add(SqlHelper.CreateParameterObject("@CapTren", SqlDbType.NVarChar, ParameterDirection.Input, captren));
                    arrParameters.Add(SqlHelper.CreateParameterObject("@UserID", SqlDbType.Int, ParameterDirection.Input, MyCommon.CurrentUserID));
                    SqlHelper.ExecuteNonQuery(CommandType.Text, sqlInsertTuDien, arrParameters);
                }

                #endregion chuyen doi tu dien CapHoc

                #region chuyen doi tu dien ChienTr
                TuDien = "ChienTr";
                MaDM = MyConst.TD.ChienTr.Ma;
                dtTuDien = SqlHelper_Convert.ExecuteDataTable(CommandType.Text, "Select * From " + TuDien);
                foreach (DataRow dr in dtTuDien.Rows)
                {
                    lblTrangThai.Text = "Đang cập nhật từ điển " + TuDien + ": " + dr["Ma"].ToString();

                    Application.DoEvents();

                    arrParameters.Clear();
                    arrParameters.Add(SqlHelper.CreateParameterObject("@Deleted", SqlDbType.Bit, ParameterDirection.Input, dr["An_Hien"]));
                    arrParameters.Add(SqlHelper.CreateParameterObject("@TuDienID", SqlDbType.Int, ParameterDirection.Input, dr["ID"].ToString()));
                    arrParameters.Add(SqlHelper.CreateParameterObject("@DauMoiID", SqlDbType.Int, ParameterDirection.Input, MyCommon.CurrentUserDauMoiID));
                    parentID = null;
                    if (dr["Ma"].ToString().Length > 3)
                    {
                        try
                        {
                            parentID = Util.ToInt(SqlHelper_Convert.ExecuteScalar(CommandType.Text, "Select ID From " + TuDien + " Where Ma='" + dr["Ma"].ToString().Substring(0, dr["Ma"].ToString().Length - 3) + "'"));
                        }
                        catch
                        {
                        }
                    }
                    arrParameters.Add(SqlHelper.CreateParameterObject("@ParentID", SqlDbType.Int, ParameterDirection.Input, parentID));

                    arrParameters.Add(SqlHelper.CreateParameterObject("@TenGoi", SqlDbType.NVarChar, ParameterDirection.Input, Converter.TCVN3ToUnicode(dr["Ten"].ToString())));
                    arrParameters.Add(SqlHelper.CreateParameterObject("@MaDanhMuc", SqlDbType.NVarChar, ParameterDirection.Input, MaDM));
                    captren = "";
                    maTem = dr["Ma"].ToString();

                    while (maTem != "")
                    {
                        try
                        {
                            captren = SqlHelper_Convert.ExecuteScalar(CommandType.Text, "Select ID From " + TuDien + " Where Ma='" + maTem + "'").ToString() + ";" + captren;
                            maTem = maTem.Substring(0, maTem.Length - 3);
                        }
                        catch
                        {
                            break;
                        }
                    }
                    captren = ";" + captren;

                    arrParameters.Add(SqlHelper.CreateParameterObject("@CapTren", SqlDbType.NVarChar, ParameterDirection.Input, captren));
                    arrParameters.Add(SqlHelper.CreateParameterObject("@UserID", SqlDbType.Int, ParameterDirection.Input, MyCommon.CurrentUserID));
                    SqlHelper.ExecuteNonQuery(CommandType.Text, sqlInsertTuDien, arrParameters);
                }

                #endregion chuyen doi tu dien ChienTr


                #region chuyen doi tu dien Chuc
                TuDien = "Chuc";
                MaDM = MyConst.TD.Chuc.Ma;
                dtTuDien = SqlHelper_Convert.ExecuteDataTable(CommandType.Text, "Select * From " + TuDien);
                foreach (DataRow dr in dtTuDien.Rows)
                {
                    lblTrangThai.Text = "Đang cập nhật từ điển " + TuDien + ": " + dr["Ma"].ToString();

                    Application.DoEvents();

                    arrParameters.Clear();
                    arrParameters.Add(SqlHelper.CreateParameterObject("@Deleted", SqlDbType.Bit, ParameterDirection.Input, dr["An_Hien"]));
                    arrParameters.Add(SqlHelper.CreateParameterObject("@TuDienID", SqlDbType.Int, ParameterDirection.Input, dr["ID"].ToString()));
                    arrParameters.Add(SqlHelper.CreateParameterObject("@DauMoiID", SqlDbType.Int, ParameterDirection.Input, MyCommon.CurrentUserDauMoiID));
                    parentID = null;
                    if (dr["Ma"].ToString().Length > 3)
                    {
                        try
                        {
                            parentID = Util.ToInt(SqlHelper_Convert.ExecuteScalar(CommandType.Text, "Select ID From " + TuDien + " Where Ma='" + dr["Ma"].ToString().Substring(0, dr["Ma"].ToString().Length - 3) + "'"));
                        }
                        catch
                        {
                        }
                    }
                    arrParameters.Add(SqlHelper.CreateParameterObject("@ParentID", SqlDbType.Int, ParameterDirection.Input, parentID));

                    arrParameters.Add(SqlHelper.CreateParameterObject("@TenGoi", SqlDbType.NVarChar, ParameterDirection.Input, Converter.TCVN3ToUnicode(dr["Ten"].ToString())));
                    arrParameters.Add(SqlHelper.CreateParameterObject("@MaDanhMuc", SqlDbType.NVarChar, ParameterDirection.Input, MaDM));
                    captren = "";
                    maTem = dr["Ma"].ToString();

                    while (maTem != "")
                    {
                        try
                        {
                            captren = SqlHelper_Convert.ExecuteScalar(CommandType.Text, "Select ID From " + TuDien + " Where Ma='" + maTem + "'").ToString() + ";" + captren;
                            maTem = maTem.Substring(0, maTem.Length - 3);
                        }
                        catch
                        {
                            break;
                        }
                    }
                    captren = ";" + captren;

                    arrParameters.Add(SqlHelper.CreateParameterObject("@CapTren", SqlDbType.NVarChar, ParameterDirection.Input, captren));
                    arrParameters.Add(SqlHelper.CreateParameterObject("@UserID", SqlDbType.Int, ParameterDirection.Input, MyCommon.CurrentUserID));
                    SqlHelper.ExecuteNonQuery(CommandType.Text, sqlInsertTuDien, arrParameters);
                }

                #endregion chuyen doi tu dien Chuc


                #region chuyen doi tu dien CVCD
                TuDien = "CVCD";
                MaDM = MyConst.TD.CVCD.Ma;
                dtTuDien = SqlHelper_Convert.ExecuteDataTable(CommandType.Text, "Select * From " + TuDien);
                foreach (DataRow dr in dtTuDien.Rows)
                {
                    lblTrangThai.Text = "Đang cập nhật từ điển " + TuDien + ": " + dr["Ma"].ToString();

                    Application.DoEvents();

                    arrParameters.Clear();
                    arrParameters.Add(SqlHelper.CreateParameterObject("@Deleted", SqlDbType.Bit, ParameterDirection.Input, dr["An_Hien"]));
                    arrParameters.Add(SqlHelper.CreateParameterObject("@TuDienID", SqlDbType.Int, ParameterDirection.Input, dr["ID"].ToString()));
                    arrParameters.Add(SqlHelper.CreateParameterObject("@DauMoiID", SqlDbType.Int, ParameterDirection.Input, MyCommon.CurrentUserDauMoiID));
                    parentID = null;
                    if (dr["Ma"].ToString().Length > 3)
                    {
                        try
                        {
                            parentID = Util.ToInt(SqlHelper_Convert.ExecuteScalar(CommandType.Text, "Select ID From " + TuDien + " Where Ma='" + dr["Ma"].ToString().Substring(0, dr["Ma"].ToString().Length - 3) + "'"));
                        }
                        catch
                        {
                        }
                    }
                    arrParameters.Add(SqlHelper.CreateParameterObject("@ParentID", SqlDbType.Int, ParameterDirection.Input, parentID));

                    arrParameters.Add(SqlHelper.CreateParameterObject("@TenGoi", SqlDbType.NVarChar, ParameterDirection.Input, Converter.TCVN3ToUnicode(dr["Ten"].ToString())));
                    arrParameters.Add(SqlHelper.CreateParameterObject("@MaDanhMuc", SqlDbType.NVarChar, ParameterDirection.Input, MaDM));
                    captren = "";
                    maTem = dr["Ma"].ToString();

                    while (maTem != "")
                    {
                        try
                        {
                            captren = SqlHelper_Convert.ExecuteScalar(CommandType.Text, "Select ID From " + TuDien + " Where Ma='" + maTem + "'").ToString() + ";" + captren;
                            maTem = maTem.Substring(0, maTem.Length - 3);
                        }
                        catch
                        {
                            break;
                        }
                    }
                    captren = ";" + captren;

                    arrParameters.Add(SqlHelper.CreateParameterObject("@CapTren", SqlDbType.NVarChar, ParameterDirection.Input, captren));
                    arrParameters.Add(SqlHelper.CreateParameterObject("@UserID", SqlDbType.Int, ParameterDirection.Input, MyCommon.CurrentUserID));
                    SqlHelper.ExecuteNonQuery(CommandType.Text, sqlInsertTuDien, arrParameters);
                }

                #endregion chuyen doi tu dien CVCD

                #region chuyen doi tu dien CVDang
                TuDien = "CVDang";
                MaDM = MyConst.TD.CVDang.Ma;
                dtTuDien = SqlHelper_Convert.ExecuteDataTable(CommandType.Text, "Select * From " + TuDien);
                foreach (DataRow dr in dtTuDien.Rows)
                {
                    lblTrangThai.Text = "Đang cập nhật từ điển " + TuDien + ": " + dr["Ma"].ToString();

                    Application.DoEvents();

                    arrParameters.Clear();
                    arrParameters.Add(SqlHelper.CreateParameterObject("@Deleted", SqlDbType.Bit, ParameterDirection.Input, dr["An_Hien"]));
                    arrParameters.Add(SqlHelper.CreateParameterObject("@TuDienID", SqlDbType.Int, ParameterDirection.Input, dr["ID"].ToString()));
                    arrParameters.Add(SqlHelper.CreateParameterObject("@DauMoiID", SqlDbType.Int, ParameterDirection.Input, MyCommon.CurrentUserDauMoiID));
                    parentID = null;
                    if (dr["Ma"].ToString().Length > 3)
                    {
                        try
                        {
                            parentID = Util.ToInt(SqlHelper_Convert.ExecuteScalar(CommandType.Text, "Select ID From " + TuDien + " Where Ma='" + dr["Ma"].ToString().Substring(0, dr["Ma"].ToString().Length - 3) + "'"));
                        }
                        catch
                        {
                        }
                    }
                    arrParameters.Add(SqlHelper.CreateParameterObject("@ParentID", SqlDbType.Int, ParameterDirection.Input, parentID));

                    arrParameters.Add(SqlHelper.CreateParameterObject("@TenGoi", SqlDbType.NVarChar, ParameterDirection.Input, Converter.TCVN3ToUnicode(dr["Ten"].ToString())));
                    arrParameters.Add(SqlHelper.CreateParameterObject("@MaDanhMuc", SqlDbType.NVarChar, ParameterDirection.Input, MaDM));
                    captren = "";
                    maTem = dr["Ma"].ToString();

                    while (maTem != "")
                    {
                        try
                        {
                            captren = SqlHelper_Convert.ExecuteScalar(CommandType.Text, "Select ID From " + TuDien + " Where Ma='" + maTem + "'").ToString() + ";" + captren;
                            maTem = maTem.Substring(0, maTem.Length - 3);
                        }
                        catch
                        {
                            break;

                        }
                    }
                    captren = ";" + captren;

                    arrParameters.Add(SqlHelper.CreateParameterObject("@CapTren", SqlDbType.NVarChar, ParameterDirection.Input, captren));
                    arrParameters.Add(SqlHelper.CreateParameterObject("@UserID", SqlDbType.Int, ParameterDirection.Input, MyCommon.CurrentUserID));
                    SqlHelper.ExecuteNonQuery(CommandType.Text, sqlInsertTuDien, arrParameters);
                }

                #endregion chuyen doi tu dien CVDang

                #region chuyen doi tu dien DanToc
                TuDien = "DanToc";
                MaDM = MyConst.TD.DanToc.Ma;
                dtTuDien = SqlHelper_Convert.ExecuteDataTable(CommandType.Text, "Select * From " + TuDien);
                foreach (DataRow dr in dtTuDien.Rows)
                {
                    lblTrangThai.Text = "Đang cập nhật từ điển " + TuDien + ": " + dr["Ma"].ToString();

                    Application.DoEvents();

                    arrParameters.Clear();
                    arrParameters.Add(SqlHelper.CreateParameterObject("@Deleted", SqlDbType.Bit, ParameterDirection.Input, dr["An_Hien"]));
                    arrParameters.Add(SqlHelper.CreateParameterObject("@TuDienID", SqlDbType.Int, ParameterDirection.Input, dr["ID"].ToString()));
                    arrParameters.Add(SqlHelper.CreateParameterObject("@DauMoiID", SqlDbType.Int, ParameterDirection.Input, MyCommon.CurrentUserDauMoiID));
                    parentID = null;
                    if (dr["Ma"].ToString().Length > 3)
                    {
                        try
                        {
                            parentID = Util.ToInt(SqlHelper_Convert.ExecuteScalar(CommandType.Text, "Select ID From " + TuDien + " Where Ma='" + dr["Ma"].ToString().Substring(0, dr["Ma"].ToString().Length - 3) + "'"));
                        }
                        catch
                        {
                        }
                    }
                    arrParameters.Add(SqlHelper.CreateParameterObject("@ParentID", SqlDbType.Int, ParameterDirection.Input, parentID));

                    arrParameters.Add(SqlHelper.CreateParameterObject("@TenGoi", SqlDbType.NVarChar, ParameterDirection.Input, Converter.TCVN3ToUnicode(dr["Ten"].ToString())));
                    arrParameters.Add(SqlHelper.CreateParameterObject("@MaDanhMuc", SqlDbType.NVarChar, ParameterDirection.Input, MaDM));
                    captren = "";
                    maTem = dr["Ma"].ToString();

                    while (maTem != "")
                    {
                        try
                        {
                            captren = SqlHelper_Convert.ExecuteScalar(CommandType.Text, "Select ID From " + TuDien + " Where Ma='" + maTem + "'").ToString() + ";" + captren;
                            maTem = maTem.Substring(0, maTem.Length - 3);
                        }
                        catch
                        {
                            break;
                        }
                    }
                    captren = ";" + captren;

                    arrParameters.Add(SqlHelper.CreateParameterObject("@CapTren", SqlDbType.NVarChar, ParameterDirection.Input, captren));
                    arrParameters.Add(SqlHelper.CreateParameterObject("@UserID", SqlDbType.Int, ParameterDirection.Input, MyCommon.CurrentUserID));
                    SqlHelper.ExecuteNonQuery(CommandType.Text, sqlInsertTuDien, arrParameters);
                }

                #endregion chuyen doi tu dien DanToc


                #region chuyen doi tu dien HocHam
                TuDien = "HocHam";
                MaDM = MyConst.TD.HocHam.Ma;
                dtTuDien = SqlHelper_Convert.ExecuteDataTable(CommandType.Text, "Select * From " + TuDien);
                foreach (DataRow dr in dtTuDien.Rows)
                {
                    lblTrangThai.Text = "Đang cập nhật từ điển " + TuDien + ": " + dr["Ma"].ToString();

                    Application.DoEvents();

                    arrParameters.Clear();
                    arrParameters.Add(SqlHelper.CreateParameterObject("@Deleted", SqlDbType.Bit, ParameterDirection.Input, dr["An_Hien"]));
                    arrParameters.Add(SqlHelper.CreateParameterObject("@TuDienID", SqlDbType.Int, ParameterDirection.Input, dr["ID"].ToString()));
                    arrParameters.Add(SqlHelper.CreateParameterObject("@DauMoiID", SqlDbType.Int, ParameterDirection.Input, MyCommon.CurrentUserDauMoiID));
                    parentID = null;
                    if (dr["Ma"].ToString().Length > 3)
                    {
                        try
                        {
                            parentID = Util.ToInt(SqlHelper_Convert.ExecuteScalar(CommandType.Text, "Select ID From " + TuDien + " Where Ma='" + dr["Ma"].ToString().Substring(0, dr["Ma"].ToString().Length - 3) + "'"));
                        }
                        catch
                        {
                        }
                    }
                    arrParameters.Add(SqlHelper.CreateParameterObject("@ParentID", SqlDbType.Int, ParameterDirection.Input, parentID));

                    arrParameters.Add(SqlHelper.CreateParameterObject("@TenGoi", SqlDbType.NVarChar, ParameterDirection.Input, Converter.TCVN3ToUnicode(dr["Ten"].ToString())));
                    arrParameters.Add(SqlHelper.CreateParameterObject("@MaDanhMuc", SqlDbType.NVarChar, ParameterDirection.Input, MaDM));
                    captren = "";
                    maTem = dr["Ma"].ToString();

                    while (maTem != "")
                    {
                        try
                        {
                            captren = SqlHelper_Convert.ExecuteScalar(CommandType.Text, "Select ID From " + TuDien + " Where Ma='" + maTem + "'").ToString() + ";" + captren;
                            maTem = maTem.Substring(0, maTem.Length - 3);
                        }
                        catch
                        {
                            break;
                        }
                    }
                    captren = ";" + captren;

                    arrParameters.Add(SqlHelper.CreateParameterObject("@CapTren", SqlDbType.NVarChar, ParameterDirection.Input, captren));
                    arrParameters.Add(SqlHelper.CreateParameterObject("@UserID", SqlDbType.Int, ParameterDirection.Input, MyCommon.CurrentUserID));
                    SqlHelper.ExecuteNonQuery(CommandType.Text, sqlInsertTuDien, arrParameters);
                }

                #endregion chuyen doi tu dien HocHam


                #region chuyen doi tu dien HocVi
                TuDien = "HocVi";
                MaDM = MyConst.TD.HocVi.Ma;
                dtTuDien = SqlHelper_Convert.ExecuteDataTable(CommandType.Text, "Select * From " + TuDien);
                foreach (DataRow dr in dtTuDien.Rows)
                {
                    lblTrangThai.Text = "Đang cập nhật từ điển " + TuDien + ": " + dr["Ma"].ToString();

                    Application.DoEvents();

                    arrParameters.Clear();
                    arrParameters.Add(SqlHelper.CreateParameterObject("@Deleted", SqlDbType.Bit, ParameterDirection.Input, dr["An_Hien"]));
                    arrParameters.Add(SqlHelper.CreateParameterObject("@TuDienID", SqlDbType.Int, ParameterDirection.Input, dr["ID"].ToString()));
                    arrParameters.Add(SqlHelper.CreateParameterObject("@DauMoiID", SqlDbType.Int, ParameterDirection.Input, MyCommon.CurrentUserDauMoiID));
                    parentID = null;
                    if (dr["Ma"].ToString().Length > 3)
                    {
                        try
                        {
                            parentID = Util.ToInt(SqlHelper_Convert.ExecuteScalar(CommandType.Text, "Select ID From " + TuDien + " Where Ma='" + dr["Ma"].ToString().Substring(0, dr["Ma"].ToString().Length - 3) + "'"));
                        }
                        catch
                        {
                        }
                    }
                    arrParameters.Add(SqlHelper.CreateParameterObject("@ParentID", SqlDbType.Int, ParameterDirection.Input, parentID));

                    arrParameters.Add(SqlHelper.CreateParameterObject("@TenGoi", SqlDbType.NVarChar, ParameterDirection.Input, Converter.TCVN3ToUnicode(dr["Ten"].ToString())));
                    arrParameters.Add(SqlHelper.CreateParameterObject("@MaDanhMuc", SqlDbType.NVarChar, ParameterDirection.Input, MaDM));
                    captren = "";
                    maTem = dr["Ma"].ToString();

                    while (maTem != "")
                    {
                        try
                        {
                            captren = SqlHelper_Convert.ExecuteScalar(CommandType.Text, "Select ID From " + TuDien + " Where Ma='" + maTem + "'").ToString() + ";" + captren;
                            maTem = maTem.Substring(0, maTem.Length - 3);
                        }
                        catch
                        {
                            break;
                        }
                    }
                    captren = ";" + captren;

                    arrParameters.Add(SqlHelper.CreateParameterObject("@CapTren", SqlDbType.NVarChar, ParameterDirection.Input, captren));
                    arrParameters.Add(SqlHelper.CreateParameterObject("@UserID", SqlDbType.Int, ParameterDirection.Input, MyCommon.CurrentUserID));
                    SqlHelper.ExecuteNonQuery(CommandType.Text, sqlInsertTuDien, arrParameters);
                }

                #endregion chuyen doi tu dien HocVi

                #region chuyen doi tu dien HS_Luong
                //TuDien = "HS_Luong";
                //MaDM = MyConst.TD.HS_Luong.Ma;
                //dtTuDien = SqlHelper_Convert.ExecuteDataTable(CommandType.Text, "Select * From " + TuDien);
                //foreach (DataRow dr in dtTuDien.Rows)
                //{
                //    lblTrangThai.Text = "Đang cập nhật từ điển " + TuDien + ": " + dr["Ma"].ToString();

                //    Application.DoEvents();

                //    arrParameters.Clear();
                //    arrParameters.Add(SqlHelper.CreateParameterObject("@Deleted", SqlDbType.Bit, ParameterDirection.Input, dr["An_Hien"]));
                //    arrParameters.Add(SqlHelper.CreateParameterObject("@TuDienID", SqlDbType.Int, ParameterDirection.Input, dr["ID"].ToString()));
                //    arrParameters.Add(SqlHelper.CreateParameterObject("@DauMoiID", SqlDbType.Int, ParameterDirection.Input, Common.CurrentUserDauMoiID));
                //    parentID = null;
                //    if (dr["Ma"].ToString().Length > 3)
                //    {
                //        try
                //        {
                //            parentID = Util.ToInt(SqlHelper_Convert.ExecuteScalar(CommandType.Text,"Select ID From " + TuDien + " Where Ma='" + dr["Ma"].ToString().Substring(0, dr["Ma"].ToString().Length - 3) + "'"));
                //        }
                //        catch
                //        {
                //        }
                //    }
                //    arrParameters.Add(SqlHelper.CreateParameterObject("@ParentID", SqlDbType.Int, ParameterDirection.Input, parentID));

                //    arrParameters.Add(SqlHelper.CreateParameterObject("@TenGoi", SqlDbType.NVarChar, ParameterDirection.Input, Converter.TCVN3ToUnicode(dr["Ten"].ToString())));
                //    arrParameters.Add(SqlHelper.CreateParameterObject("@MaDanhMuc", SqlDbType.NVarChar, ParameterDirection.Input, MaDM));
                //    captren = "";
                //    maTem = dr["Ma"].ToString();

                //    while (maTem != "")
                //    {
                //        try
                //        {
                //            captren = SqlHelper_Convert.ExecuteScalar(CommandType.Text, "Select ID From " + TuDien + " Where Ma='" + maTem + "'").ToString() + ";" + captren;
                //            maTem = maTem.Substring(0, maTem.Length - 3);
                //        }
                //        catch
                //        {
                //            break;
                //        }
                //    }
                //    captren = ";" + captren;

                //    arrParameters.Add(SqlHelper.CreateParameterObject("@CapTren", SqlDbType.NVarChar, ParameterDirection.Input, captren));
                //    arrParameters.Add(SqlHelper.CreateParameterObject("@UserID", SqlDbType.Int, ParameterDirection.Input, Common.CurrentUserID));
                //    SqlHelper.ExecuteNonQuery( CommandType.Text, sqlInsertTuDien, arrParameters);
                //}

                #endregion chuyen doi tu dien HS_Luong


                #region chuyen doi tu dien Khoi_CT
                TuDien = "[Khoi-CT]";
                MaDM = MyConst.TD.Khoi_CT.Ma;
                dtTuDien = SqlHelper_Convert.ExecuteDataTable(CommandType.Text, "Select * From " + TuDien);
                foreach (DataRow dr in dtTuDien.Rows)
                {
                    lblTrangThai.Text = "Đang cập nhật từ điển " + TuDien + ": " + dr["Ma"].ToString();

                    Application.DoEvents();

                    arrParameters.Clear();
                    arrParameters.Add(SqlHelper.CreateParameterObject("@Deleted", SqlDbType.Bit, ParameterDirection.Input, dr["An_Hien"]));
                    arrParameters.Add(SqlHelper.CreateParameterObject("@TuDienID", SqlDbType.Int, ParameterDirection.Input, dr["ID"].ToString()));
                    arrParameters.Add(SqlHelper.CreateParameterObject("@DauMoiID", SqlDbType.Int, ParameterDirection.Input, MyCommon.CurrentUserDauMoiID));
                    parentID = null;
                    if (dr["Ma"].ToString().Length > 3)
                    {
                        try
                        {
                            parentID = Util.ToInt(SqlHelper_Convert.ExecuteScalar(CommandType.Text, "Select ID From " + TuDien + " Where Ma='" + dr["Ma"].ToString().Substring(0, dr["Ma"].ToString().Length - 3) + "'"));
                        }
                        catch
                        {
                        }
                    }
                    arrParameters.Add(SqlHelper.CreateParameterObject("@ParentID", SqlDbType.Int, ParameterDirection.Input, parentID));

                    arrParameters.Add(SqlHelper.CreateParameterObject("@TenGoi", SqlDbType.NVarChar, ParameterDirection.Input, Converter.TCVN3ToUnicode(dr["Ten"].ToString())));
                    arrParameters.Add(SqlHelper.CreateParameterObject("@MaDanhMuc", SqlDbType.NVarChar, ParameterDirection.Input, MaDM));
                    captren = "";
                    maTem = dr["Ma"].ToString();

                    while (maTem != "")
                    {
                        try
                        {
                            captren = SqlHelper_Convert.ExecuteScalar(CommandType.Text, "Select ID From " + TuDien + " Where Ma='" + maTem + "'").ToString() + ";" + captren;
                            maTem = maTem.Substring(0, maTem.Length - 3);
                        }
                        catch
                        {
                            break;
                        }
                    }
                    captren = ";" + captren;

                    arrParameters.Add(SqlHelper.CreateParameterObject("@CapTren", SqlDbType.NVarChar, ParameterDirection.Input, captren));
                    arrParameters.Add(SqlHelper.CreateParameterObject("@UserID", SqlDbType.Int, ParameterDirection.Input, MyCommon.CurrentUserID));
                    SqlHelper.ExecuteNonQuery(CommandType.Text, sqlInsertTuDien, arrParameters);
                }

                #endregion chuyen doi tu dien Khoi_CT

                #region chuyen doi tu dien LDo_Giam
                TuDien = "LDo_Giam";
                MaDM = MyConst.TD.LDo_Giam.Ma;
                dtTuDien = SqlHelper_Convert.ExecuteDataTable(CommandType.Text, "Select * From " + TuDien);
                foreach (DataRow dr in dtTuDien.Rows)
                {
                    lblTrangThai.Text = "Đang cập nhật từ điển " + TuDien + ": " + dr["Ma"].ToString();

                    Application.DoEvents();

                    arrParameters.Clear();
                    arrParameters.Add(SqlHelper.CreateParameterObject("@Deleted", SqlDbType.Bit, ParameterDirection.Input, dr["An_Hien"]));
                    arrParameters.Add(SqlHelper.CreateParameterObject("@TuDienID", SqlDbType.Int, ParameterDirection.Input, dr["ID"].ToString()));
                    arrParameters.Add(SqlHelper.CreateParameterObject("@DauMoiID", SqlDbType.Int, ParameterDirection.Input, MyCommon.CurrentUserDauMoiID));
                    parentID = null;
                    if (dr["Ma"].ToString().Length > 3)
                    {
                        try
                        {
                            parentID = Util.ToInt(SqlHelper_Convert.ExecuteScalar(CommandType.Text, "Select ID From " + TuDien + " Where Ma='" + dr["Ma"].ToString().Substring(0, dr["Ma"].ToString().Length - 3) + "'"));
                        }
                        catch
                        {
                        }
                    }
                    arrParameters.Add(SqlHelper.CreateParameterObject("@ParentID", SqlDbType.Int, ParameterDirection.Input, parentID));

                    arrParameters.Add(SqlHelper.CreateParameterObject("@TenGoi", SqlDbType.NVarChar, ParameterDirection.Input, Converter.TCVN3ToUnicode(dr["Ten"].ToString())));
                    arrParameters.Add(SqlHelper.CreateParameterObject("@MaDanhMuc", SqlDbType.NVarChar, ParameterDirection.Input, MaDM));
                    captren = "";
                    maTem = dr["Ma"].ToString();

                    while (maTem != "")
                    {
                        try
                        {
                            captren = SqlHelper_Convert.ExecuteScalar(CommandType.Text, "Select ID From " + TuDien + " Where Ma='" + maTem + "'").ToString() + ";" + captren;
                            maTem = maTem.Substring(0, maTem.Length - 3);
                        }
                        catch
                        {
                            break;
                        }
                    }
                    captren = ";" + captren;

                    arrParameters.Add(SqlHelper.CreateParameterObject("@CapTren", SqlDbType.NVarChar, ParameterDirection.Input, captren));
                    arrParameters.Add(SqlHelper.CreateParameterObject("@UserID", SqlDbType.Int, ParameterDirection.Input, MyCommon.CurrentUserID));
                    SqlHelper.ExecuteNonQuery(CommandType.Text, sqlInsertTuDien, arrParameters);
                }

                #endregion chuyen doi tu dien LDo_Giam


                #region chuyen doi tu dien LDo_Tang
                TuDien = "LDo_Tang";
                MaDM = MyConst.TD.LDo_Tang.Ma;
                dtTuDien = SqlHelper_Convert.ExecuteDataTable(CommandType.Text, "Select * From " + TuDien);
                foreach (DataRow dr in dtTuDien.Rows)
                {
                    lblTrangThai.Text = "Đang cập nhật từ điển " + TuDien + ": " + dr["Ma"].ToString();

                    Application.DoEvents();

                    arrParameters.Clear();
                    arrParameters.Add(SqlHelper.CreateParameterObject("@Deleted", SqlDbType.Bit, ParameterDirection.Input, dr["An_Hien"]));
                    arrParameters.Add(SqlHelper.CreateParameterObject("@TuDienID", SqlDbType.Int, ParameterDirection.Input, dr["ID"].ToString()));
                    arrParameters.Add(SqlHelper.CreateParameterObject("@DauMoiID", SqlDbType.Int, ParameterDirection.Input, MyCommon.CurrentUserDauMoiID));
                    parentID = null;
                    if (dr["Ma"].ToString().Length > 3)
                    {
                        try
                        {
                            parentID = Util.ToInt(SqlHelper_Convert.ExecuteScalar(CommandType.Text, "Select ID From " + TuDien + " Where Ma='" + dr["Ma"].ToString().Substring(0, dr["Ma"].ToString().Length - 3) + "'"));
                        }
                        catch
                        {
                        }
                    }
                    arrParameters.Add(SqlHelper.CreateParameterObject("@ParentID", SqlDbType.Int, ParameterDirection.Input, parentID));

                    arrParameters.Add(SqlHelper.CreateParameterObject("@TenGoi", SqlDbType.NVarChar, ParameterDirection.Input, Converter.TCVN3ToUnicode(dr["Ten"].ToString())));
                    arrParameters.Add(SqlHelper.CreateParameterObject("@MaDanhMuc", SqlDbType.NVarChar, ParameterDirection.Input, MaDM));
                    captren = "";
                    maTem = dr["Ma"].ToString();

                    while (maTem != "")
                    {
                        try
                        {
                            captren = SqlHelper_Convert.ExecuteScalar(CommandType.Text, "Select ID From " + TuDien + " Where Ma='" + maTem + "'").ToString() + ";" + captren;
                            maTem = maTem.Substring(0, maTem.Length - 3);
                        }
                        catch
                        {
                            break;
                        }
                    }
                    captren = ";" + captren;

                    arrParameters.Add(SqlHelper.CreateParameterObject("@CapTren", SqlDbType.NVarChar, ParameterDirection.Input, captren));
                    arrParameters.Add(SqlHelper.CreateParameterObject("@UserID", SqlDbType.Int, ParameterDirection.Input, MyCommon.CurrentUserID));
                    SqlHelper.ExecuteNonQuery(CommandType.Text, sqlInsertTuDien, arrParameters);
                }

                #endregion chuyen doi tu dien LDo_Tang


                #region chuyen doi tu dien LoaiCanBo
                TuDien = "LoaiCB";
                MaDM = MyConst.TD.LoaiCB.Ma;
                dtTuDien = SqlHelper_Convert.ExecuteDataTable(CommandType.Text, "Select * From " + TuDien);
                foreach (DataRow dr in dtTuDien.Rows)
                {
                    lblTrangThai.Text = "Đang cập nhật từ điển " + TuDien + ": " + dr["Ma"].ToString();

                    Application.DoEvents();

                    arrParameters.Clear();
                    arrParameters.Add(SqlHelper.CreateParameterObject("@Deleted", SqlDbType.Bit, ParameterDirection.Input, dr["An_Hien"]));
                    arrParameters.Add(SqlHelper.CreateParameterObject("@TuDienID", SqlDbType.Int, ParameterDirection.Input, dr["ID"].ToString()));
                    arrParameters.Add(SqlHelper.CreateParameterObject("@DauMoiID", SqlDbType.Int, ParameterDirection.Input, MyCommon.CurrentUserDauMoiID));
                    parentID = null;
                    if (dr["Ma"].ToString().Length > 3)
                    {
                        try
                        {
                            parentID = Util.ToInt(SqlHelper_Convert.ExecuteScalar(CommandType.Text, "Select ID From " + TuDien + " Where Ma='" + dr["Ma"].ToString().Substring(0, dr["Ma"].ToString().Length - 3) + "'"));
                        }
                        catch
                        {
                        }
                    }
                    arrParameters.Add(SqlHelper.CreateParameterObject("@ParentID", SqlDbType.Int, ParameterDirection.Input, parentID));

                    arrParameters.Add(SqlHelper.CreateParameterObject("@TenGoi", SqlDbType.NVarChar, ParameterDirection.Input, Converter.TCVN3ToUnicode(dr["Ten"].ToString())));
                    arrParameters.Add(SqlHelper.CreateParameterObject("@MaDanhMuc", SqlDbType.NVarChar, ParameterDirection.Input, MaDM));
                    captren = "";
                    maTem = dr["Ma"].ToString();

                    while (maTem != "")
                    {
                        try
                        {
                            captren = SqlHelper_Convert.ExecuteScalar(CommandType.Text, "Select ID From " + TuDien + " Where Ma='" + maTem + "'").ToString() + ";" + captren;
                            maTem = maTem.Substring(0, maTem.Length - 3);
                        }
                        catch
                        {
                            break;
                        }
                    }
                    captren = ";" + captren;

                    arrParameters.Add(SqlHelper.CreateParameterObject("@CapTren", SqlDbType.NVarChar, ParameterDirection.Input, captren));
                    arrParameters.Add(SqlHelper.CreateParameterObject("@UserID", SqlDbType.Int, ParameterDirection.Input, MyCommon.CurrentUserID));
                    SqlHelper.ExecuteNonQuery(CommandType.Text, sqlInsertTuDien, arrParameters);
                }

                #endregion chuyen doi tu dien LoaiCanBo


                #region chuyen doi tu dien LoaiDV
                TuDien = "LoaiDV";
                MaDM = MyConst.TD.LoaiDV.Ma;
                dtTuDien = SqlHelper_Convert.ExecuteDataTable(CommandType.Text, "Select * From " + TuDien);
                foreach (DataRow dr in dtTuDien.Rows)
                {
                    lblTrangThai.Text = "Đang cập nhật từ điển " + TuDien + ": " + dr["Ma"].ToString();

                    Application.DoEvents();

                    arrParameters.Clear();
                    arrParameters.Add(SqlHelper.CreateParameterObject("@Deleted", SqlDbType.Bit, ParameterDirection.Input, dr["An_Hien"]));
                    arrParameters.Add(SqlHelper.CreateParameterObject("@TuDienID", SqlDbType.Int, ParameterDirection.Input, dr["ID"].ToString()));
                    arrParameters.Add(SqlHelper.CreateParameterObject("@DauMoiID", SqlDbType.Int, ParameterDirection.Input, MyCommon.CurrentUserDauMoiID));
                    parentID = null;
                    if (dr["Ma"].ToString().Length > 3)
                    {
                        try
                        {
                            parentID = Util.ToInt(SqlHelper_Convert.ExecuteScalar(CommandType.Text, "Select ID From " + TuDien + " Where Ma='" + dr["Ma"].ToString().Substring(0, dr["Ma"].ToString().Length - 3) + "'"));
                        }
                        catch
                        {
                        }
                    }
                    arrParameters.Add(SqlHelper.CreateParameterObject("@ParentID", SqlDbType.Int, ParameterDirection.Input, parentID));

                    arrParameters.Add(SqlHelper.CreateParameterObject("@TenGoi", SqlDbType.NVarChar, ParameterDirection.Input, Converter.TCVN3ToUnicode(dr["Ten"].ToString())));
                    arrParameters.Add(SqlHelper.CreateParameterObject("@MaDanhMuc", SqlDbType.NVarChar, ParameterDirection.Input, MaDM));
                    captren = "";
                    maTem = dr["Ma"].ToString();

                    while (maTem != "")
                    {
                        try
                        {
                            captren = SqlHelper_Convert.ExecuteScalar(CommandType.Text, "Select ID From " + TuDien + " Where Ma='" + maTem + "'").ToString() + ";" + captren;
                            maTem = maTem.Substring(0, maTem.Length - 3);
                        }
                        catch
                        {
                            break;
                        }
                    }
                    captren = ";" + captren;

                    arrParameters.Add(SqlHelper.CreateParameterObject("@CapTren", SqlDbType.NVarChar, ParameterDirection.Input, captren));
                    arrParameters.Add(SqlHelper.CreateParameterObject("@UserID", SqlDbType.Int, ParameterDirection.Input, MyCommon.CurrentUserID));
                    SqlHelper.ExecuteNonQuery(CommandType.Text, sqlInsertTuDien, arrParameters);
                }

                #endregion chuyen doi tu dien LoaiDV


                #region chuyen doi tu dien LoaiHinh
                TuDien = "LoaiHinh";
                MaDM = MyConst.TD.LoaiHinh.Ma;
                dtTuDien = SqlHelper_Convert.ExecuteDataTable(CommandType.Text, "Select * From " + TuDien);
                foreach (DataRow dr in dtTuDien.Rows)
                {
                    lblTrangThai.Text = "Đang cập nhật từ điển " + TuDien + ": " + dr["Ma"].ToString();

                    Application.DoEvents();

                    arrParameters.Clear();
                    arrParameters.Add(SqlHelper.CreateParameterObject("@Deleted", SqlDbType.Bit, ParameterDirection.Input, dr["An_Hien"]));
                    arrParameters.Add(SqlHelper.CreateParameterObject("@TuDienID", SqlDbType.Int, ParameterDirection.Input, dr["ID"].ToString()));
                    arrParameters.Add(SqlHelper.CreateParameterObject("@DauMoiID", SqlDbType.Int, ParameterDirection.Input, MyCommon.CurrentUserDauMoiID));
                    parentID = null;
                    if (dr["Ma"].ToString().Length > 3)
                    {
                        try
                        {
                            parentID = Util.ToInt(SqlHelper_Convert.ExecuteScalar(CommandType.Text, "Select ID From " + TuDien + " Where Ma='" + dr["Ma"].ToString().Substring(0, dr["Ma"].ToString().Length - 3) + "'"));
                        }
                        catch
                        {
                        }
                    }
                    arrParameters.Add(SqlHelper.CreateParameterObject("@ParentID", SqlDbType.Int, ParameterDirection.Input, parentID));

                    arrParameters.Add(SqlHelper.CreateParameterObject("@TenGoi", SqlDbType.NVarChar, ParameterDirection.Input, Converter.TCVN3ToUnicode(dr["Ten"].ToString())));
                    arrParameters.Add(SqlHelper.CreateParameterObject("@MaDanhMuc", SqlDbType.NVarChar, ParameterDirection.Input, MaDM));
                    captren = "";
                    maTem = dr["Ma"].ToString();

                    while (maTem != "")
                    {
                        try
                        {
                            captren = SqlHelper_Convert.ExecuteScalar(CommandType.Text, "Select ID From " + TuDien + " Where Ma='" + maTem + "'").ToString() + ";" + captren;
                            maTem = maTem.Substring(0, maTem.Length - 3);
                        }
                        catch
                        {
                            break;
                        }
                    }
                    captren = ";" + captren;

                    arrParameters.Add(SqlHelper.CreateParameterObject("@CapTren", SqlDbType.NVarChar, ParameterDirection.Input, captren));
                    arrParameters.Add(SqlHelper.CreateParameterObject("@UserID", SqlDbType.Int, ParameterDirection.Input, MyCommon.CurrentUserID));
                    SqlHelper.ExecuteNonQuery(CommandType.Text, sqlInsertTuDien, arrParameters);
                }

                #endregion chuyen doi tu dien LoaiHinh


                #region chuyen doi tu dien LoaiNha
                TuDien = "LoaiNha";
                MaDM = MyConst.TD.LoaiNha.Ma;
                dtTuDien = SqlHelper_Convert.ExecuteDataTable(CommandType.Text, "Select * From " + TuDien);
                foreach (DataRow dr in dtTuDien.Rows)
                {
                    lblTrangThai.Text = "Đang cập nhật từ điển " + TuDien + ": " + dr["Ma"].ToString();

                    Application.DoEvents();

                    arrParameters.Clear();
                    arrParameters.Add(SqlHelper.CreateParameterObject("@Deleted", SqlDbType.Bit, ParameterDirection.Input, false));
                    arrParameters.Add(SqlHelper.CreateParameterObject("@TuDienID", SqlDbType.Int, ParameterDirection.Input, dr["ID"].ToString()));
                    arrParameters.Add(SqlHelper.CreateParameterObject("@DauMoiID", SqlDbType.Int, ParameterDirection.Input, MyCommon.CurrentUserDauMoiID));
                    parentID = null;
                    if (dr["Ma"].ToString().Length > 3)
                    {
                        try
                        {
                            parentID = Util.ToInt(SqlHelper_Convert.ExecuteScalar(CommandType.Text, "Select ID From " + TuDien + " Where Ma='" + dr["Ma"].ToString().Substring(0, dr["Ma"].ToString().Length - 3) + "'"));
                        }
                        catch
                        {
                        }
                    }
                    arrParameters.Add(SqlHelper.CreateParameterObject("@ParentID", SqlDbType.Int, ParameterDirection.Input, parentID));

                    arrParameters.Add(SqlHelper.CreateParameterObject("@TenGoi", SqlDbType.NVarChar, ParameterDirection.Input, Converter.TCVN3ToUnicode(dr["Ten"].ToString())));
                    arrParameters.Add(SqlHelper.CreateParameterObject("@MaDanhMuc", SqlDbType.NVarChar, ParameterDirection.Input, MaDM));
                    captren = "";
                    maTem = dr["Ma"].ToString();

                    while (maTem != "")
                    {
                        try
                        {
                            captren = SqlHelper_Convert.ExecuteScalar(CommandType.Text, "Select ID From " + TuDien + " Where Ma='" + maTem + "'").ToString() + ";" + captren;
                            maTem = maTem.Substring(0, maTem.Length - 3);
                        }
                        catch
                        {
                            break;
                        }
                    }
                    captren = ";" + captren;

                    arrParameters.Add(SqlHelper.CreateParameterObject("@CapTren", SqlDbType.NVarChar, ParameterDirection.Input, captren));
                    arrParameters.Add(SqlHelper.CreateParameterObject("@UserID", SqlDbType.Int, ParameterDirection.Input, MyCommon.CurrentUserID));
                    SqlHelper.ExecuteNonQuery(CommandType.Text, sqlInsertTuDien, arrParameters);
                }

                #endregion chuyen doi tu dien LoaiNha


                #region chuyen doi tu dien LoaiTN
                TuDien = "LoaiTN";
                MaDM = MyConst.TD.LoaiTN.Ma;
                dtTuDien = SqlHelper_Convert.ExecuteDataTable(CommandType.Text, "Select * From " + TuDien);
                foreach (DataRow dr in dtTuDien.Rows)
                {
                    lblTrangThai.Text = "Đang cập nhật từ điển " + TuDien + ": " + dr["Ma"].ToString();

                    Application.DoEvents();

                    arrParameters.Clear();
                    arrParameters.Add(SqlHelper.CreateParameterObject("@Deleted", SqlDbType.Bit, ParameterDirection.Input, dr["An_Hien"]));
                    arrParameters.Add(SqlHelper.CreateParameterObject("@TuDienID", SqlDbType.Int, ParameterDirection.Input, dr["ID"].ToString()));
                    arrParameters.Add(SqlHelper.CreateParameterObject("@DauMoiID", SqlDbType.Int, ParameterDirection.Input, MyCommon.CurrentUserDauMoiID));
                    parentID = null;
                    if (dr["Ma"].ToString().Length > 3)
                    {
                        try
                        {
                            parentID = Util.ToInt(SqlHelper_Convert.ExecuteScalar(CommandType.Text, "Select ID From " + TuDien + " Where Ma='" + dr["Ma"].ToString().Substring(0, dr["Ma"].ToString().Length - 3) + "'"));
                        }
                        catch
                        {
                        }
                    }
                    arrParameters.Add(SqlHelper.CreateParameterObject("@ParentID", SqlDbType.Int, ParameterDirection.Input, parentID));

                    arrParameters.Add(SqlHelper.CreateParameterObject("@TenGoi", SqlDbType.NVarChar, ParameterDirection.Input, Converter.TCVN3ToUnicode(dr["Ten"].ToString())));
                    arrParameters.Add(SqlHelper.CreateParameterObject("@MaDanhMuc", SqlDbType.NVarChar, ParameterDirection.Input, MaDM));
                    captren = "";
                    maTem = dr["Ma"].ToString();

                    while (maTem != "")
                    {
                        try
                        {
                            captren = SqlHelper_Convert.ExecuteScalar(CommandType.Text, "Select ID From " + TuDien + " Where Ma='" + maTem + "'").ToString() + ";" + captren;
                            maTem = maTem.Substring(0, maTem.Length - 3);
                        }
                        catch
                        {
                            break;
                        }
                    }
                    captren = ";" + captren;

                    arrParameters.Add(SqlHelper.CreateParameterObject("@CapTren", SqlDbType.NVarChar, ParameterDirection.Input, captren));
                    arrParameters.Add(SqlHelper.CreateParameterObject("@UserID", SqlDbType.Int, ParameterDirection.Input, MyCommon.CurrentUserID));
                    SqlHelper.ExecuteNonQuery(CommandType.Text, sqlInsertTuDien, arrParameters);
                }

                #endregion chuyen doi tu dien LoaiTN


                #region chuyen doi tu dien Ng_CNCT
                TuDien = "[Ng-CNCT]";
                MaDM = MyConst.TD.Ng_CNCT.Ma;
                dtTuDien = SqlHelper_Convert.ExecuteDataTable(CommandType.Text, "Select * From " + TuDien);
                foreach (DataRow dr in dtTuDien.Rows)
                {
                    lblTrangThai.Text = "Đang cập nhật từ điển " + TuDien + ": " + dr["Ma"].ToString();

                    Application.DoEvents();

                    arrParameters.Clear();
                    arrParameters.Add(SqlHelper.CreateParameterObject("@Deleted", SqlDbType.Bit, ParameterDirection.Input, dr["An_Hien"]));
                    arrParameters.Add(SqlHelper.CreateParameterObject("@TuDienID", SqlDbType.Int, ParameterDirection.Input, dr["ID"].ToString()));
                    arrParameters.Add(SqlHelper.CreateParameterObject("@DauMoiID", SqlDbType.Int, ParameterDirection.Input, MyCommon.CurrentUserDauMoiID));
                    parentID = null;
                    if (dr["Ma"].ToString().Length > 3)
                    {
                        try
                        {
                            parentID = Util.ToInt(SqlHelper_Convert.ExecuteScalar(CommandType.Text, "Select ID From " + TuDien + " Where Ma='" + dr["Ma"].ToString().Substring(0, dr["Ma"].ToString().Length - 3) + "'"));
                        }
                        catch
                        {
                        }
                    }
                    arrParameters.Add(SqlHelper.CreateParameterObject("@ParentID", SqlDbType.Int, ParameterDirection.Input, parentID));

                    arrParameters.Add(SqlHelper.CreateParameterObject("@TenGoi", SqlDbType.NVarChar, ParameterDirection.Input, Converter.TCVN3ToUnicode(dr["Ten"].ToString())));
                    arrParameters.Add(SqlHelper.CreateParameterObject("@MaDanhMuc", SqlDbType.NVarChar, ParameterDirection.Input, MaDM));
                    captren = "";
                    maTem = dr["Ma"].ToString();

                    while (maTem != "")
                    {
                        try
                        {
                            captren = SqlHelper_Convert.ExecuteScalar(CommandType.Text, "Select ID From " + TuDien + " Where Ma='" + maTem + "'").ToString() + ";" + captren;
                            maTem = maTem.Substring(0, maTem.Length - 3);
                        }
                        catch
                        {
                            break;
                        }
                    }
                    captren = ";" + captren;

                    arrParameters.Add(SqlHelper.CreateParameterObject("@CapTren", SqlDbType.NVarChar, ParameterDirection.Input, captren));
                    arrParameters.Add(SqlHelper.CreateParameterObject("@UserID", SqlDbType.Int, ParameterDirection.Input, MyCommon.CurrentUserID));
                    SqlHelper.ExecuteNonQuery(CommandType.Text, sqlInsertTuDien, arrParameters);
                }

                #endregion chuyen doi tu dien Ng_CNCT


                #region chuyen doi tu dien Ng_CNDT
                TuDien = "[Ng-CNDT]";
                MaDM = MyConst.TD.Ng_CNDT.Ma;
                dtTuDien = SqlHelper_Convert.ExecuteDataTable(CommandType.Text, "Select * From " + TuDien);
                foreach (DataRow dr in dtTuDien.Rows)
                {
                    lblTrangThai.Text = "Đang cập nhật từ điển " + TuDien + ": " + dr["Ma"].ToString();

                    Application.DoEvents();

                    arrParameters.Clear();
                    arrParameters.Add(SqlHelper.CreateParameterObject("@Deleted", SqlDbType.Bit, ParameterDirection.Input, dr["An_Hien"]));
                    arrParameters.Add(SqlHelper.CreateParameterObject("@TuDienID", SqlDbType.Int, ParameterDirection.Input, dr["ID"].ToString()));
                    arrParameters.Add(SqlHelper.CreateParameterObject("@DauMoiID", SqlDbType.Int, ParameterDirection.Input, MyCommon.CurrentUserDauMoiID));
                    parentID = null;
                    if (dr["Ma"].ToString().Length > 3)
                    {
                        try
                        {
                            parentID = Util.ToInt(SqlHelper_Convert.ExecuteScalar(CommandType.Text, "Select ID From " + TuDien + " Where Ma='" + dr["Ma"].ToString().Substring(0, dr["Ma"].ToString().Length - 3) + "'"));
                        }
                        catch
                        {
                        }
                    }
                    arrParameters.Add(SqlHelper.CreateParameterObject("@ParentID", SqlDbType.Int, ParameterDirection.Input, parentID));

                    arrParameters.Add(SqlHelper.CreateParameterObject("@TenGoi", SqlDbType.NVarChar, ParameterDirection.Input, Converter.TCVN3ToUnicode(dr["Ten"].ToString())));
                    arrParameters.Add(SqlHelper.CreateParameterObject("@MaDanhMuc", SqlDbType.NVarChar, ParameterDirection.Input, MaDM));
                    captren = "";
                    maTem = dr["Ma"].ToString();

                    while (maTem != "")
                    {
                        try
                        {
                            captren = SqlHelper_Convert.ExecuteScalar(CommandType.Text, "Select ID From " + TuDien + " Where Ma='" + maTem + "'").ToString() + ";" + captren;
                            maTem = maTem.Substring(0, maTem.Length - 3);
                        }
                        catch
                        {
                            break;
                        }
                    }
                    captren = ";" + captren;

                    arrParameters.Add(SqlHelper.CreateParameterObject("@CapTren", SqlDbType.NVarChar, ParameterDirection.Input, captren));
                    arrParameters.Add(SqlHelper.CreateParameterObject("@UserID", SqlDbType.Int, ParameterDirection.Input, MyCommon.CurrentUserID));
                    SqlHelper.ExecuteNonQuery(CommandType.Text, sqlInsertTuDien, arrParameters);
                }

                #endregion chuyen doi tu dien Ng_CNDT


                #region chuyen doi tu dien NgoaiN
                TuDien = "NgoaiN";
                MaDM = MyConst.TD.NgoaiNgu.Ma;
                dtTuDien = SqlHelper_Convert.ExecuteDataTable(CommandType.Text, "Select * From " + TuDien);
                foreach (DataRow dr in dtTuDien.Rows)
                {
                    lblTrangThai.Text = "Đang cập nhật từ điển " + TuDien + ": " + dr["Ma"].ToString();

                    Application.DoEvents();

                    arrParameters.Clear();
                    arrParameters.Add(SqlHelper.CreateParameterObject("@Deleted", SqlDbType.Bit, ParameterDirection.Input, dr["An_Hien"]));
                    arrParameters.Add(SqlHelper.CreateParameterObject("@TuDienID", SqlDbType.Int, ParameterDirection.Input, dr["ID"].ToString()));
                    arrParameters.Add(SqlHelper.CreateParameterObject("@DauMoiID", SqlDbType.Int, ParameterDirection.Input, MyCommon.CurrentUserDauMoiID));
                    parentID = null;
                    if (dr["Ma"].ToString().Length > 3)
                    {
                        try
                        {
                            parentID = Util.ToInt(SqlHelper_Convert.ExecuteScalar(CommandType.Text, "Select ID From " + TuDien + " Where Ma='" + dr["Ma"].ToString().Substring(0, dr["Ma"].ToString().Length - 3) + "'"));
                        }
                        catch
                        {
                        }
                    }
                    arrParameters.Add(SqlHelper.CreateParameterObject("@ParentID", SqlDbType.Int, ParameterDirection.Input, parentID));

                    arrParameters.Add(SqlHelper.CreateParameterObject("@TenGoi", SqlDbType.NVarChar, ParameterDirection.Input, Converter.TCVN3ToUnicode(dr["Ten"].ToString())));
                    arrParameters.Add(SqlHelper.CreateParameterObject("@MaDanhMuc", SqlDbType.NVarChar, ParameterDirection.Input, MaDM));
                    captren = "";
                    maTem = dr["Ma"].ToString();

                    while (maTem != "")
                    {
                        try
                        {
                            captren = SqlHelper_Convert.ExecuteScalar(CommandType.Text, "Select ID From " + TuDien + " Where Ma='" + maTem + "'").ToString() + ";" + captren;
                            maTem = maTem.Substring(0, maTem.Length - 3);
                        }
                        catch
                        {
                            break;
                        }
                    }
                    captren = ";" + captren;

                    arrParameters.Add(SqlHelper.CreateParameterObject("@CapTren", SqlDbType.NVarChar, ParameterDirection.Input, captren));
                    arrParameters.Add(SqlHelper.CreateParameterObject("@UserID", SqlDbType.Int, ParameterDirection.Input, MyCommon.CurrentUserID));
                    SqlHelper.ExecuteNonQuery(CommandType.Text, sqlInsertTuDien, arrParameters);
                }

                #endregion chuyen doi tu dien NgoaiN

                #region chuyen doi tu dien Nguon
                TuDien = "Nguon";
                MaDM = MyConst.TD.Nguon.Ma;
                dtTuDien = SqlHelper_Convert.ExecuteDataTable(CommandType.Text, "Select * From " + TuDien);
                foreach (DataRow dr in dtTuDien.Rows)
                {
                    lblTrangThai.Text = "Đang cập nhật từ điển " + TuDien + ": " + dr["Ma"].ToString();

                    Application.DoEvents();

                    arrParameters.Clear();
                    arrParameters.Add(SqlHelper.CreateParameterObject("@Deleted", SqlDbType.Bit, ParameterDirection.Input, dr["An_Hien"]));
                    arrParameters.Add(SqlHelper.CreateParameterObject("@TuDienID", SqlDbType.Int, ParameterDirection.Input, dr["ID"].ToString()));
                    arrParameters.Add(SqlHelper.CreateParameterObject("@DauMoiID", SqlDbType.Int, ParameterDirection.Input, MyCommon.CurrentUserDauMoiID));
                    parentID = null;
                    if (dr["Ma"].ToString().Length > 3)
                    {
                        try
                        {
                            parentID = Util.ToInt(SqlHelper_Convert.ExecuteScalar(CommandType.Text, "Select ID From " + TuDien + " Where Ma='" + dr["Ma"].ToString().Substring(0, dr["Ma"].ToString().Length - 3) + "'"));
                        }
                        catch
                        {
                        }
                    }
                    arrParameters.Add(SqlHelper.CreateParameterObject("@ParentID", SqlDbType.Int, ParameterDirection.Input, parentID));

                    arrParameters.Add(SqlHelper.CreateParameterObject("@TenGoi", SqlDbType.NVarChar, ParameterDirection.Input, Converter.TCVN3ToUnicode(dr["Ten"].ToString())));
                    arrParameters.Add(SqlHelper.CreateParameterObject("@MaDanhMuc", SqlDbType.NVarChar, ParameterDirection.Input, MaDM));
                    captren = "";
                    maTem = dr["Ma"].ToString();

                    while (maTem != "")
                    {
                        try
                        {
                            captren = SqlHelper_Convert.ExecuteScalar(CommandType.Text, "Select ID From " + TuDien + " Where Ma='" + maTem + "'").ToString() + ";" + captren;
                            maTem = maTem.Substring(0, maTem.Length - 3);
                        }
                        catch
                        {
                            break;
                        }
                    }
                    captren = ";" + captren;

                    arrParameters.Add(SqlHelper.CreateParameterObject("@CapTren", SqlDbType.NVarChar, ParameterDirection.Input, captren));
                    arrParameters.Add(SqlHelper.CreateParameterObject("@UserID", SqlDbType.Int, ParameterDirection.Input, MyCommon.CurrentUserID));
                    SqlHelper.ExecuteNonQuery(CommandType.Text, sqlInsertTuDien, arrParameters);
                }

                #endregion chuyen doi tu dien Nguon

                #region chuyen doi tu dien NguonGoc
                TuDien = "NguonGoc";
                MaDM = MyConst.TD.NguonGoc.Ma;
                dtTuDien = SqlHelper_Convert.ExecuteDataTable(CommandType.Text, "Select * From " + TuDien);
                foreach (DataRow dr in dtTuDien.Rows)
                {
                    lblTrangThai.Text = "Đang cập nhật từ điển " + TuDien + ": " + dr["Ma"].ToString();

                    Application.DoEvents();

                    arrParameters.Clear();
                    arrParameters.Add(SqlHelper.CreateParameterObject("@Deleted", SqlDbType.Bit, ParameterDirection.Input, false));
                    arrParameters.Add(SqlHelper.CreateParameterObject("@TuDienID", SqlDbType.Int, ParameterDirection.Input, dr["ID"].ToString()));
                    arrParameters.Add(SqlHelper.CreateParameterObject("@DauMoiID", SqlDbType.Int, ParameterDirection.Input, MyCommon.CurrentUserDauMoiID));
                    parentID = null;
                    if (dr["Ma"].ToString().Length > 3)
                    {
                        try
                        {
                            parentID = Util.ToInt(SqlHelper_Convert.ExecuteScalar(CommandType.Text, "Select ID From " + TuDien + " Where Ma='" + dr["Ma"].ToString().Substring(0, dr["Ma"].ToString().Length - 3) + "'"));
                        }
                        catch
                        {
                        }
                    }
                    arrParameters.Add(SqlHelper.CreateParameterObject("@ParentID", SqlDbType.Int, ParameterDirection.Input, parentID));

                    arrParameters.Add(SqlHelper.CreateParameterObject("@TenGoi", SqlDbType.NVarChar, ParameterDirection.Input, Converter.TCVN3ToUnicode(dr["Ten"].ToString())));
                    arrParameters.Add(SqlHelper.CreateParameterObject("@MaDanhMuc", SqlDbType.NVarChar, ParameterDirection.Input, MaDM));
                    captren = "";
                    maTem = dr["Ma"].ToString();

                    while (maTem != "")
                    {
                        try
                        {
                            captren = SqlHelper_Convert.ExecuteScalar(CommandType.Text, "Select ID From " + TuDien + " Where Ma='" + maTem + "'").ToString() + ";" + captren;
                            maTem = maTem.Substring(0, maTem.Length - 3);
                        }
                        catch
                        {
                            break;
                        }
                    }
                    captren = ";" + captren;

                    arrParameters.Add(SqlHelper.CreateParameterObject("@CapTren", SqlDbType.NVarChar, ParameterDirection.Input, captren));
                    arrParameters.Add(SqlHelper.CreateParameterObject("@UserID", SqlDbType.Int, ParameterDirection.Input, MyCommon.CurrentUserID));
                    SqlHelper.ExecuteNonQuery(CommandType.Text, sqlInsertTuDien, arrParameters);
                }

                #endregion chuyen doi tu dien NguonGoc


                #region chuyen doi tu dien Nuoc
                TuDien = "Nuoc";
                MaDM = MyConst.TD.Nuoc.Ma;
                dtTuDien = SqlHelper_Convert.ExecuteDataTable(CommandType.Text, "Select * From " + TuDien);
                foreach (DataRow dr in dtTuDien.Rows)
                {
                    lblTrangThai.Text = "Đang cập nhật từ điển " + TuDien + ": " + dr["Ma"].ToString();

                    Application.DoEvents();

                    arrParameters.Clear();
                    arrParameters.Add(SqlHelper.CreateParameterObject("@Deleted", SqlDbType.Bit, ParameterDirection.Input, dr["An_Hien"]));
                    arrParameters.Add(SqlHelper.CreateParameterObject("@TuDienID", SqlDbType.Int, ParameterDirection.Input, dr["ID"].ToString()));
                    arrParameters.Add(SqlHelper.CreateParameterObject("@DauMoiID", SqlDbType.Int, ParameterDirection.Input, MyCommon.CurrentUserDauMoiID));
                    parentID = null;
                    if (dr["Ma"].ToString().Length > 3)
                    {
                        try
                        {
                            parentID = Util.ToInt(SqlHelper_Convert.ExecuteScalar(CommandType.Text, "Select ID From " + TuDien + " Where Ma='" + dr["Ma"].ToString().Substring(0, dr["Ma"].ToString().Length - 3) + "'"));
                        }
                        catch
                        {
                        }
                    }
                    arrParameters.Add(SqlHelper.CreateParameterObject("@ParentID", SqlDbType.Int, ParameterDirection.Input, parentID));

                    arrParameters.Add(SqlHelper.CreateParameterObject("@TenGoi", SqlDbType.NVarChar, ParameterDirection.Input, Converter.TCVN3ToUnicode(dr["Ten"].ToString())));
                    arrParameters.Add(SqlHelper.CreateParameterObject("@MaDanhMuc", SqlDbType.NVarChar, ParameterDirection.Input, MaDM));
                    captren = "";
                    maTem = dr["Ma"].ToString();

                    while (maTem != "")
                    {
                        try
                        {
                            captren = SqlHelper_Convert.ExecuteScalar(CommandType.Text, "Select ID From " + TuDien + " Where Ma='" + maTem + "'").ToString() + ";" + captren;
                            maTem = maTem.Substring(0, maTem.Length - 3);
                        }
                        catch
                        {
                            break;
                        }
                    }
                    captren = ";" + captren;

                    arrParameters.Add(SqlHelper.CreateParameterObject("@CapTren", SqlDbType.NVarChar, ParameterDirection.Input, captren));
                    arrParameters.Add(SqlHelper.CreateParameterObject("@UserID", SqlDbType.Int, ParameterDirection.Input, MyCommon.CurrentUserID));
                    SqlHelper.ExecuteNonQuery(CommandType.Text, sqlInsertTuDien, arrParameters);
                }

                #endregion chuyen doi tu dien Nuoc


                #region chuyen doi tu dien QuanHe
                TuDien = "QuanHe";
                MaDM = MyConst.TD.QuanHe.Ma;
                dtTuDien = SqlHelper_Convert.ExecuteDataTable(CommandType.Text, "Select * From " + TuDien);
                foreach (DataRow dr in dtTuDien.Rows)
                {
                    lblTrangThai.Text = "Đang cập nhật từ điển " + TuDien + ": " + dr["Ma"].ToString();

                    Application.DoEvents();

                    arrParameters.Clear();
                    arrParameters.Add(SqlHelper.CreateParameterObject("@Deleted", SqlDbType.Bit, ParameterDirection.Input, dr["An_Hien"]));
                    arrParameters.Add(SqlHelper.CreateParameterObject("@TuDienID", SqlDbType.Int, ParameterDirection.Input, dr["ID"].ToString()));
                    arrParameters.Add(SqlHelper.CreateParameterObject("@DauMoiID", SqlDbType.Int, ParameterDirection.Input, MyCommon.CurrentUserDauMoiID));
                    parentID = null;
                    if (dr["Ma"].ToString().Length > 3)
                    {
                        try
                        {
                            parentID = Util.ToInt(SqlHelper_Convert.ExecuteScalar(CommandType.Text, "Select ID From " + TuDien + " Where Ma='" + dr["Ma"].ToString().Substring(0, dr["Ma"].ToString().Length - 3) + "'"));
                        }
                        catch
                        {
                        }
                    }
                    arrParameters.Add(SqlHelper.CreateParameterObject("@ParentID", SqlDbType.Int, ParameterDirection.Input, parentID));

                    arrParameters.Add(SqlHelper.CreateParameterObject("@TenGoi", SqlDbType.NVarChar, ParameterDirection.Input, Converter.TCVN3ToUnicode(dr["Ten"].ToString())));
                    arrParameters.Add(SqlHelper.CreateParameterObject("@MaDanhMuc", SqlDbType.NVarChar, ParameterDirection.Input, MaDM));
                    captren = "";
                    maTem = dr["Ma"].ToString();

                    while (maTem != "")
                    {
                        try
                        {
                            captren = SqlHelper_Convert.ExecuteScalar(CommandType.Text, "Select ID From " + TuDien + " Where Ma='" + maTem + "'").ToString() + ";" + captren;
                            maTem = maTem.Substring(0, maTem.Length - 3);
                        }
                        catch
                        {
                            break;
                        }
                    }
                    captren = ";" + captren;

                    arrParameters.Add(SqlHelper.CreateParameterObject("@CapTren", SqlDbType.NVarChar, ParameterDirection.Input, captren));
                    arrParameters.Add(SqlHelper.CreateParameterObject("@UserID", SqlDbType.Int, ParameterDirection.Input, MyCommon.CurrentUserID));
                    SqlHelper.ExecuteNonQuery(CommandType.Text, sqlInsertTuDien, arrParameters);
                }

                #endregion chuyen doi tu dien QuanHe


                #region chuyen doi tu dien Que
                TuDien = "Que";
                MaDM = MyConst.TD.Que.Ma;
                dtTuDien = SqlHelper_Convert.ExecuteDataTable(CommandType.Text, "Select * From " + TuDien);
                foreach (DataRow dr in dtTuDien.Rows)
                {
                    lblTrangThai.Text = "Đang cập nhật từ điển " + TuDien + ": " + dr["Ma"].ToString();

                    Application.DoEvents();

                    arrParameters.Clear();
                    arrParameters.Add(SqlHelper.CreateParameterObject("@Deleted", SqlDbType.Bit, ParameterDirection.Input, dr["An_Hien"]));
                    arrParameters.Add(SqlHelper.CreateParameterObject("@TuDienID", SqlDbType.Int, ParameterDirection.Input, dr["ID"].ToString()));
                    arrParameters.Add(SqlHelper.CreateParameterObject("@DauMoiID", SqlDbType.Int, ParameterDirection.Input, MyCommon.CurrentUserDauMoiID));
                    parentID = null;
                    if (dr["Ma"].ToString().Length > 3)
                    {
                        try
                        {
                            parentID = Util.ToInt(SqlHelper_Convert.ExecuteScalar(CommandType.Text, "Select ID From " + TuDien + " Where Ma='" + dr["Ma"].ToString().Substring(0, dr["Ma"].ToString().Length - 3) + "'"));
                        }
                        catch
                        {
                        }
                    }
                    arrParameters.Add(SqlHelper.CreateParameterObject("@ParentID", SqlDbType.Int, ParameterDirection.Input, parentID));

                    arrParameters.Add(SqlHelper.CreateParameterObject("@TenGoi", SqlDbType.NVarChar, ParameterDirection.Input, Converter.TCVN3ToUnicode(dr["Ten"].ToString())));
                    arrParameters.Add(SqlHelper.CreateParameterObject("@MaDanhMuc", SqlDbType.NVarChar, ParameterDirection.Input, MaDM));
                    captren = "";
                    maTem = dr["Ma"].ToString();

                    while (maTem != "")
                    {
                        try
                        {
                            captren = SqlHelper_Convert.ExecuteScalar(CommandType.Text, "Select ID From " + TuDien + " Where Ma='" + maTem + "'").ToString() + ";" + captren;
                            maTem = maTem.Substring(0, maTem.Length - 3);
                        }
                        catch
                        {
                            break;
                        }
                    }
                    captren = ";" + captren;

                    arrParameters.Add(SqlHelper.CreateParameterObject("@CapTren", SqlDbType.NVarChar, ParameterDirection.Input, captren));
                    arrParameters.Add(SqlHelper.CreateParameterObject("@UserID", SqlDbType.Int, ParameterDirection.Input, MyCommon.CurrentUserID));
                    SqlHelper.ExecuteNonQuery(CommandType.Text, sqlInsertTuDien, arrParameters);
                }

                #endregion chuyen doi tu dien Que


                #region chuyen doi tu dien SK_DGia
                TuDien = "SK_DGia";
                MaDM = MyConst.TD.SK_DGia.Ma;
                dtTuDien = SqlHelper_Convert.ExecuteDataTable(CommandType.Text, "Select * From " + TuDien);
                foreach (DataRow dr in dtTuDien.Rows)
                {
                    lblTrangThai.Text = "Đang cập nhật từ điển " + TuDien + ": " + dr["Ma"].ToString();

                    Application.DoEvents();

                    arrParameters.Clear();
                    arrParameters.Add(SqlHelper.CreateParameterObject("@Deleted", SqlDbType.Bit, ParameterDirection.Input, dr["An_Hien"]));
                    arrParameters.Add(SqlHelper.CreateParameterObject("@TuDienID", SqlDbType.Int, ParameterDirection.Input, dr["ID"].ToString()));
                    arrParameters.Add(SqlHelper.CreateParameterObject("@DauMoiID", SqlDbType.Int, ParameterDirection.Input, MyCommon.CurrentUserDauMoiID));
                    parentID = null;
                    if (dr["Ma"].ToString().Length > 3)
                    {
                        try
                        {
                            parentID = Util.ToInt(SqlHelper_Convert.ExecuteScalar(CommandType.Text, "Select ID From " + TuDien + " Where Ma='" + dr["Ma"].ToString().Substring(0, dr["Ma"].ToString().Length - 3) + "'"));
                        }
                        catch
                        {
                        }
                    }
                    arrParameters.Add(SqlHelper.CreateParameterObject("@ParentID", SqlDbType.Int, ParameterDirection.Input, parentID));

                    arrParameters.Add(SqlHelper.CreateParameterObject("@TenGoi", SqlDbType.NVarChar, ParameterDirection.Input, Converter.TCVN3ToUnicode(dr["Ten"].ToString())));
                    arrParameters.Add(SqlHelper.CreateParameterObject("@MaDanhMuc", SqlDbType.NVarChar, ParameterDirection.Input, MaDM));
                    captren = "";
                    maTem = dr["Ma"].ToString();

                    while (maTem != "")
                    {
                        try
                        {
                            captren = SqlHelper_Convert.ExecuteScalar(CommandType.Text, "Select ID From " + TuDien + " Where Ma='" + maTem + "'").ToString() + ";" + captren;
                            maTem = maTem.Substring(0, maTem.Length - 3);
                        }
                        catch
                        {
                            break;
                        }
                    }
                    captren = ";" + captren;

                    arrParameters.Add(SqlHelper.CreateParameterObject("@CapTren", SqlDbType.NVarChar, ParameterDirection.Input, captren));
                    arrParameters.Add(SqlHelper.CreateParameterObject("@UserID", SqlDbType.Int, ParameterDirection.Input, MyCommon.CurrentUserID));
                    SqlHelper.ExecuteNonQuery(CommandType.Text, sqlInsertTuDien, arrParameters);
                }

                #endregion chuyen doi tu dien SK_DGia

                #region chuyen doi tu dien SucK
                TuDien = "SucK";
                MaDM = MyConst.TD.SucK.Ma;
                dtTuDien = SqlHelper_Convert.ExecuteDataTable(CommandType.Text, "Select * From " + TuDien);
                foreach (DataRow dr in dtTuDien.Rows)
                {
                    lblTrangThai.Text = "Đang cập nhật từ điển " + TuDien + ": " + dr["Ma"].ToString();

                    Application.DoEvents();

                    arrParameters.Clear();
                    arrParameters.Add(SqlHelper.CreateParameterObject("@Deleted", SqlDbType.Bit, ParameterDirection.Input, dr["An_Hien"]));
                    arrParameters.Add(SqlHelper.CreateParameterObject("@TuDienID", SqlDbType.Int, ParameterDirection.Input, dr["ID"].ToString()));
                    arrParameters.Add(SqlHelper.CreateParameterObject("@DauMoiID", SqlDbType.Int, ParameterDirection.Input, MyCommon.CurrentUserDauMoiID));
                    parentID = null;
                    if (dr["Ma"].ToString().Length > 3)
                    {
                        try
                        {
                            parentID = Util.ToInt(SqlHelper_Convert.ExecuteScalar(CommandType.Text, "Select ID From " + TuDien + " Where Ma='" + dr["Ma"].ToString().Substring(0, dr["Ma"].ToString().Length - 3) + "'"));
                        }
                        catch
                        {
                        }
                    }
                    arrParameters.Add(SqlHelper.CreateParameterObject("@ParentID", SqlDbType.Int, ParameterDirection.Input, parentID));

                    arrParameters.Add(SqlHelper.CreateParameterObject("@TenGoi", SqlDbType.NVarChar, ParameterDirection.Input, Converter.TCVN3ToUnicode(dr["Ten"].ToString())));
                    arrParameters.Add(SqlHelper.CreateParameterObject("@MaDanhMuc", SqlDbType.NVarChar, ParameterDirection.Input, MaDM));
                    captren = "";
                    maTem = dr["Ma"].ToString();

                    while (maTem != "")
                    {
                        try
                        {
                            captren = SqlHelper_Convert.ExecuteScalar(CommandType.Text, "Select ID From " + TuDien + " Where Ma='" + maTem + "'").ToString() + ";" + captren;
                            maTem = maTem.Substring(0, maTem.Length - 3);
                        }
                        catch
                        {
                            break;
                        }
                    }
                    captren = ";" + captren;

                    arrParameters.Add(SqlHelper.CreateParameterObject("@CapTren", SqlDbType.NVarChar, ParameterDirection.Input, captren));
                    arrParameters.Add(SqlHelper.CreateParameterObject("@UserID", SqlDbType.Int, ParameterDirection.Input, MyCommon.CurrentUserID));
                    SqlHelper.ExecuteNonQuery(CommandType.Text, sqlInsertTuDien, arrParameters);
                }

                #endregion chuyen doi tu dien SucK

                #region chuyen doi tu dien SuDung
                TuDien = "SuDung";
                MaDM = MyConst.TD.SuDung.Ma;
                dtTuDien = SqlHelper_Convert.ExecuteDataTable(CommandType.Text, "Select * From " + TuDien);
                foreach (DataRow dr in dtTuDien.Rows)
                {
                    lblTrangThai.Text = "Đang cập nhật từ điển " + TuDien + ": " + dr["Ma"].ToString();

                    Application.DoEvents();

                    arrParameters.Clear();
                    arrParameters.Add(SqlHelper.CreateParameterObject("@Deleted", SqlDbType.Bit, ParameterDirection.Input, dr["An_Hien"]));
                    arrParameters.Add(SqlHelper.CreateParameterObject("@TuDienID", SqlDbType.Int, ParameterDirection.Input, dr["ID"].ToString()));
                    arrParameters.Add(SqlHelper.CreateParameterObject("@DauMoiID", SqlDbType.Int, ParameterDirection.Input, MyCommon.CurrentUserDauMoiID));
                    parentID = null;
                    if (dr["Ma"].ToString().Length > 3)
                    {
                        try
                        {
                            parentID = Util.ToInt(SqlHelper_Convert.ExecuteScalar(CommandType.Text, "Select ID From " + TuDien + " Where Ma='" + dr["Ma"].ToString().Substring(0, dr["Ma"].ToString().Length - 3) + "'"));
                        }
                        catch
                        {
                        }
                    }
                    arrParameters.Add(SqlHelper.CreateParameterObject("@ParentID", SqlDbType.Int, ParameterDirection.Input, parentID));

                    arrParameters.Add(SqlHelper.CreateParameterObject("@TenGoi", SqlDbType.NVarChar, ParameterDirection.Input, Converter.TCVN3ToUnicode(dr["Ten"].ToString())));
                    arrParameters.Add(SqlHelper.CreateParameterObject("@MaDanhMuc", SqlDbType.NVarChar, ParameterDirection.Input, MaDM));
                    captren = "";
                    maTem = dr["Ma"].ToString();

                    while (maTem != "")
                    {
                        try
                        {
                            captren = SqlHelper_Convert.ExecuteScalar(CommandType.Text, "Select ID From " + TuDien + " Where Ma='" + maTem + "'").ToString() + ";" + captren;
                            maTem = maTem.Substring(0, maTem.Length - 3);
                        }
                        catch
                        {
                            break;
                        }
                    }
                    captren = ";" + captren;

                    arrParameters.Add(SqlHelper.CreateParameterObject("@CapTren", SqlDbType.NVarChar, ParameterDirection.Input, captren));
                    arrParameters.Add(SqlHelper.CreateParameterObject("@UserID", SqlDbType.Int, ParameterDirection.Input, MyCommon.CurrentUserID));
                    SqlHelper.ExecuteNonQuery(CommandType.Text, sqlInsertTuDien, arrParameters);
                }

                #endregion chuyen doi tu dien SuDung

                #region chuyen doi tu dien ThuongT
                TuDien = "ThuongT";
                MaDM = MyConst.TD.ThuongT.Ma;
                dtTuDien = SqlHelper_Convert.ExecuteDataTable(CommandType.Text, "Select * From " + TuDien);
                foreach (DataRow dr in dtTuDien.Rows)
                {
                    lblTrangThai.Text = "Đang cập nhật từ điển " + TuDien + ": " + dr["Ma"].ToString();

                    Application.DoEvents();

                    arrParameters.Clear();
                    arrParameters.Add(SqlHelper.CreateParameterObject("@Deleted", SqlDbType.Bit, ParameterDirection.Input, false));
                    arrParameters.Add(SqlHelper.CreateParameterObject("@TuDienID", SqlDbType.Int, ParameterDirection.Input, dr["ID"].ToString()));
                    arrParameters.Add(SqlHelper.CreateParameterObject("@DauMoiID", SqlDbType.Int, ParameterDirection.Input, MyCommon.CurrentUserDauMoiID));
                    parentID = null;
                    if (dr["Ma"].ToString().Length > 3)
                    {
                        try
                        {
                            parentID = Util.ToInt(SqlHelper_Convert.ExecuteScalar(CommandType.Text, "Select ID From " + TuDien + " Where Ma='" + dr["Ma"].ToString().Substring(0, dr["Ma"].ToString().Length - 3) + "'"));
                        }
                        catch
                        {
                        }
                    }
                    arrParameters.Add(SqlHelper.CreateParameterObject("@ParentID", SqlDbType.Int, ParameterDirection.Input, parentID));

                    arrParameters.Add(SqlHelper.CreateParameterObject("@TenGoi", SqlDbType.NVarChar, ParameterDirection.Input, Converter.TCVN3ToUnicode(dr["Ten"].ToString())));
                    arrParameters.Add(SqlHelper.CreateParameterObject("@MaDanhMuc", SqlDbType.NVarChar, ParameterDirection.Input, MaDM));
                    captren = "";
                    maTem = dr["Ma"].ToString();

                    while (maTem != "")
                    {
                        try
                        {
                            captren = SqlHelper_Convert.ExecuteScalar(CommandType.Text, "Select ID From " + TuDien + " Where Ma='" + maTem + "'").ToString() + ";" + captren;
                            maTem = maTem.Substring(0, maTem.Length - 3);
                        }
                        catch
                        {
                            break;
                        }
                    }
                    captren = ";" + captren;

                    arrParameters.Add(SqlHelper.CreateParameterObject("@CapTren", SqlDbType.NVarChar, ParameterDirection.Input, captren));
                    arrParameters.Add(SqlHelper.CreateParameterObject("@UserID", SqlDbType.Int, ParameterDirection.Input, MyCommon.CurrentUserID));
                    SqlHelper.ExecuteNonQuery(CommandType.Text, sqlInsertTuDien, arrParameters);
                }

                #endregion chuyen doi tu dien ThuongT

                #region chuyen doi tu dien TonGiao
                TuDien = "TonGiao";
                MaDM = MyConst.TD.TonGiao.Ma;
                dtTuDien = SqlHelper_Convert.ExecuteDataTable(CommandType.Text, "Select * From " + TuDien);
                foreach (DataRow dr in dtTuDien.Rows)
                {
                    lblTrangThai.Text = "Đang cập nhật từ điển " + TuDien + ": " + dr["Ma"].ToString();

                    Application.DoEvents();

                    arrParameters.Clear();
                    arrParameters.Add(SqlHelper.CreateParameterObject("@Deleted", SqlDbType.Bit, ParameterDirection.Input, false));
                    arrParameters.Add(SqlHelper.CreateParameterObject("@TuDienID", SqlDbType.Int, ParameterDirection.Input, dr["ID"].ToString()));
                    arrParameters.Add(SqlHelper.CreateParameterObject("@DauMoiID", SqlDbType.Int, ParameterDirection.Input, MyCommon.CurrentUserDauMoiID));
                    parentID = null;
                    if (dr["Ma"].ToString().Length > 3)
                    {
                        try
                        {
                            parentID = Util.ToInt(SqlHelper_Convert.ExecuteScalar(CommandType.Text, "Select ID From " + TuDien + " Where Ma='" + dr["Ma"].ToString().Substring(0, dr["Ma"].ToString().Length - 3) + "'"));
                        }
                        catch
                        {
                        }
                    }
                    arrParameters.Add(SqlHelper.CreateParameterObject("@ParentID", SqlDbType.Int, ParameterDirection.Input, parentID));

                    arrParameters.Add(SqlHelper.CreateParameterObject("@TenGoi", SqlDbType.NVarChar, ParameterDirection.Input, Converter.TCVN3ToUnicode(dr["Ten"].ToString())));
                    arrParameters.Add(SqlHelper.CreateParameterObject("@MaDanhMuc", SqlDbType.NVarChar, ParameterDirection.Input, MaDM));
                    captren = "";
                    maTem = dr["Ma"].ToString();

                    while (maTem != "")
                    {
                        try
                        {
                            captren = SqlHelper_Convert.ExecuteScalar(CommandType.Text, "Select ID From " + TuDien + " Where Ma='" + maTem + "'").ToString() + ";" + captren;
                            maTem = maTem.Substring(0, maTem.Length - 3);
                        }
                        catch
                        {
                            break;
                        }
                    }
                    captren = ";" + captren;

                    arrParameters.Add(SqlHelper.CreateParameterObject("@CapTren", SqlDbType.NVarChar, ParameterDirection.Input, captren));
                    arrParameters.Add(SqlHelper.CreateParameterObject("@UserID", SqlDbType.Int, ParameterDirection.Input, MyCommon.CurrentUserID));
                    SqlHelper.ExecuteNonQuery(CommandType.Text, sqlInsertTuDien, arrParameters);
                }

                #endregion chuyen doi tu dien TonGiao

                #region chuyen doi tu dien TP
                TuDien = "TP";
                MaDM = MyConst.TD.TP.Ma;
                dtTuDien = SqlHelper_Convert.ExecuteDataTable(CommandType.Text, "Select * From " + TuDien);
                foreach (DataRow dr in dtTuDien.Rows)
                {
                    lblTrangThai.Text = "Đang cập nhật từ điển " + TuDien + ": " + dr["Ma"].ToString();

                    Application.DoEvents();

                    arrParameters.Clear();
                    arrParameters.Add(SqlHelper.CreateParameterObject("@Deleted", SqlDbType.Bit, ParameterDirection.Input, false));
                    arrParameters.Add(SqlHelper.CreateParameterObject("@TuDienID", SqlDbType.Int, ParameterDirection.Input, dr["ID"].ToString()));
                    arrParameters.Add(SqlHelper.CreateParameterObject("@DauMoiID", SqlDbType.Int, ParameterDirection.Input, MyCommon.CurrentUserDauMoiID));
                    parentID = null;
                    if (dr["Ma"].ToString().Length > 3)
                    {
                        try
                        {
                            parentID = Util.ToInt(SqlHelper_Convert.ExecuteScalar(CommandType.Text, "Select ID From " + TuDien + " Where Ma='" + dr["Ma"].ToString().Substring(0, dr["Ma"].ToString().Length - 3) + "'"));
                        }
                        catch
                        {
                        }
                    }
                    arrParameters.Add(SqlHelper.CreateParameterObject("@ParentID", SqlDbType.Int, ParameterDirection.Input, parentID));

                    arrParameters.Add(SqlHelper.CreateParameterObject("@TenGoi", SqlDbType.NVarChar, ParameterDirection.Input, Converter.TCVN3ToUnicode(dr["Ten"].ToString())));
                    arrParameters.Add(SqlHelper.CreateParameterObject("@MaDanhMuc", SqlDbType.NVarChar, ParameterDirection.Input, MaDM));
                    captren = "";
                    maTem = dr["Ma"].ToString();

                    while (maTem != "")
                    {
                        try
                        {
                            captren = SqlHelper_Convert.ExecuteScalar(CommandType.Text, "Select ID From " + TuDien + " Where Ma='" + maTem + "'").ToString() + ";" + captren;
                            maTem = maTem.Substring(0, maTem.Length - 3);
                        }
                        catch
                        {
                            break;
                        }
                    }
                    captren = ";" + captren;

                    arrParameters.Add(SqlHelper.CreateParameterObject("@CapTren", SqlDbType.NVarChar, ParameterDirection.Input, captren));
                    arrParameters.Add(SqlHelper.CreateParameterObject("@UserID", SqlDbType.Int, ParameterDirection.Input, MyCommon.CurrentUserID));
                    SqlHelper.ExecuteNonQuery(CommandType.Text, sqlInsertTuDien, arrParameters);
                }

                #endregion chuyen doi tu dien TP

                #region chuyen doi tu dien Truong
                TuDien = "Truong";
                MaDM = MyConst.TD.Truong.Ma;
                dtTuDien = SqlHelper_Convert.ExecuteDataTable(CommandType.Text, "Select * From " + TuDien);
                foreach (DataRow dr in dtTuDien.Rows)
                {
                    lblTrangThai.Text = "Đang cập nhật từ điển " + TuDien + ": " + dr["Ma"].ToString();

                    Application.DoEvents();

                    arrParameters.Clear();
                    arrParameters.Add(SqlHelper.CreateParameterObject("@Deleted", SqlDbType.Bit, ParameterDirection.Input, dr["An_Hien"]));
                    arrParameters.Add(SqlHelper.CreateParameterObject("@TuDienID", SqlDbType.Int, ParameterDirection.Input, dr["ID"].ToString()));
                    arrParameters.Add(SqlHelper.CreateParameterObject("@DauMoiID", SqlDbType.Int, ParameterDirection.Input, MyCommon.CurrentUserDauMoiID));
                    parentID = null;
                    if (dr["Ma"].ToString().Length > 3)
                    {
                        try
                        {
                            parentID = Util.ToInt(SqlHelper_Convert.ExecuteScalar(CommandType.Text, "Select ID From " + TuDien + " Where Ma='" + dr["Ma"].ToString().Substring(0, dr["Ma"].ToString().Length - 3) + "'"));
                        }
                        catch
                        {
                        }
                    }
                    arrParameters.Add(SqlHelper.CreateParameterObject("@ParentID", SqlDbType.Int, ParameterDirection.Input, parentID));

                    arrParameters.Add(SqlHelper.CreateParameterObject("@TenGoi", SqlDbType.NVarChar, ParameterDirection.Input, Converter.TCVN3ToUnicode(dr["Ten"].ToString())));
                    arrParameters.Add(SqlHelper.CreateParameterObject("@MaDanhMuc", SqlDbType.NVarChar, ParameterDirection.Input, MaDM));
                    captren = "";
                    maTem = dr["Ma"].ToString();

                    while (maTem != "")
                    {
                        try
                        {
                            captren = SqlHelper_Convert.ExecuteScalar(CommandType.Text, "Select ID From " + TuDien + " Where Ma='" + maTem + "'").ToString() + ";" + captren;
                            maTem = maTem.Substring(0, maTem.Length - 3);
                        }
                        catch
                        {
                            break;
                        }
                    }
                    captren = ";" + captren;

                    arrParameters.Add(SqlHelper.CreateParameterObject("@CapTren", SqlDbType.NVarChar, ParameterDirection.Input, captren));
                    arrParameters.Add(SqlHelper.CreateParameterObject("@UserID", SqlDbType.Int, ParameterDirection.Input, MyCommon.CurrentUserID));
                    SqlHelper.ExecuteNonQuery(CommandType.Text, sqlInsertTuDien, arrParameters);
                }

                #endregion chuyen doi tu dien Truong

                #region chuyen doi tu dien VanHoa
                TuDien = "VanHoa";
                MaDM = MyConst.TD.VanHoa.Ma;
                dtTuDien = SqlHelper_Convert.ExecuteDataTable(CommandType.Text, "Select * From " + TuDien);
                foreach (DataRow dr in dtTuDien.Rows)
                {
                    lblTrangThai.Text = "Đang cập nhật từ điển " + TuDien + ": " + dr["Ma"].ToString();

                    Application.DoEvents();

                    arrParameters.Clear();
                    arrParameters.Add(SqlHelper.CreateParameterObject("@Deleted", SqlDbType.Bit, ParameterDirection.Input, false));
                    arrParameters.Add(SqlHelper.CreateParameterObject("@TuDienID", SqlDbType.Int, ParameterDirection.Input, dr["ID"].ToString()));
                    arrParameters.Add(SqlHelper.CreateParameterObject("@DauMoiID", SqlDbType.Int, ParameterDirection.Input, MyCommon.CurrentUserDauMoiID));
                    parentID = null;
                    if (dr["Ma"].ToString().Length > 3)
                    {
                        try
                        {
                            parentID = Util.ToInt(SqlHelper_Convert.ExecuteScalar(CommandType.Text, "Select ID From " + TuDien + " Where Ma='" + dr["Ma"].ToString().Substring(0, dr["Ma"].ToString().Length - 3) + "'"));
                        }
                        catch
                        {
                        }
                    }
                    arrParameters.Add(SqlHelper.CreateParameterObject("@ParentID", SqlDbType.Int, ParameterDirection.Input, parentID));

                    arrParameters.Add(SqlHelper.CreateParameterObject("@TenGoi", SqlDbType.NVarChar, ParameterDirection.Input, Converter.TCVN3ToUnicode(dr["Ten"].ToString())));
                    arrParameters.Add(SqlHelper.CreateParameterObject("@MaDanhMuc", SqlDbType.NVarChar, ParameterDirection.Input, MaDM));
                    captren = "";
                    maTem = dr["Ma"].ToString();

                    while (maTem != "")
                    {
                        try
                        {
                            captren = SqlHelper_Convert.ExecuteScalar(CommandType.Text, "Select ID From " + TuDien + " Where Ma='" + maTem + "'").ToString() + ";" + captren;
                            maTem = maTem.Substring(0, maTem.Length - 3);
                        }
                        catch
                        {
                            break;
                        }
                    }
                    captren = ";" + captren;

                    arrParameters.Add(SqlHelper.CreateParameterObject("@CapTren", SqlDbType.NVarChar, ParameterDirection.Input, captren));
                    arrParameters.Add(SqlHelper.CreateParameterObject("@UserID", SqlDbType.Int, ParameterDirection.Input, MyCommon.CurrentUserID));
                    SqlHelper.ExecuteNonQuery(CommandType.Text, sqlInsertTuDien, arrParameters);
                }

                #endregion chuyen doi tu dien VanHoa

                #region chuyen doi tu dien BienChe

                string sqlBC = "Insert Into tblBienChe(DauMoiID, ID, BoPhan_ID, ChucGoc_ID, STT, Syncode, Deleted) Values(@DauMoiID, @ID, @BoPhan_ID, @ChucGoc_ID, @STT, 0, 0) ";

                TuDien = "BienChe";
                MaDM = MyConst.TD.BienChe.Ma;
                dtTuDien = SqlHelper_Convert.ExecuteDataTable(CommandType.Text, "Select * From " + TuDien);
                foreach (DataRow dr in dtTuDien.Rows)
                {
                    try
                    {
                        lblTrangThai.Text = "Đang cập nhật từ điển " + TuDien + ": " + dr["ID"].ToString();

                        Application.DoEvents();

                        arrParameters.Clear();
                        arrParameters.Add(SqlHelper.CreateParameterObject("@DauMoiID", SqlDbType.Int, ParameterDirection.Input, MyCommon.CurrentUserDauMoiID));
                        arrParameters.Add(SqlHelper.CreateParameterObject("@ID", SqlDbType.Int, ParameterDirection.Input, dr["ID"]));
                        arrParameters.Add(SqlHelper.CreateParameterObject("@BoPhan_ID", SqlDbType.Int, ParameterDirection.Input, dr["BoPhan_ID"]));
                        arrParameters.Add(SqlHelper.CreateParameterObject("@ChucGoc_ID", SqlDbType.Int, ParameterDirection.Input, dr["ChucGoc_ID"]));
                        arrParameters.Add(SqlHelper.CreateParameterObject("@STT", SqlDbType.Int, ParameterDirection.Input, dr["SoTT"]));
                        SqlHelper.ExecuteNonQuery(CommandType.Text, sqlBC, arrParameters);
                    }
                    catch
                    {
                    }
                }

                SqlHelper.ExecuteNonQuery(CommandType.Text, "Update tblBienChe Set STT=0 Where STT Is Null");
                #endregion chuyen doi tu dien BienChe


                #region CanBo

                DataTable dtCanBo = SqlHelper_Convert.ExecuteDataTable(CommandType.Text, "Select * From CANBO ");
                string sqlCanBo = "";
                int maxKhoa = 0;
                List<SqlParameter> arrParametersCanBo = new List<SqlParameter>();

                #region SQLInsert
                sqlCanBo = "INSERT INTO  tblCanBo(DauMoiID, Khoa, So_Hieu_SQ, So_Hieu_QN, HoTen_KS " +
                                               ", BiDanh, Ho, Dem, Ten, Ten_Khac, Cap_Bac, Thang_CBac " +
                                               ", Lan_NLuong, HeSoLuong, Bac_Luong, Muc_Luong, LuongChinh, Thang_NL " +
                                               ", Chuc_Vu, Thang_CVu, Chuc_Kiem, Dung_CVCT, Loai_DV, Don_Vi_CT " +
                                               ", Khoi_CTac, Ngay_Sinh, Gioi_Tinh, Binh_Chung, Nganh_CTac, Dan_Toc_T " +
                                               ", Ton_Giao_T, Loai_CBo, Van_Hoa, CHQL, LLCT, CMNV, HocHam, HocVi, DanhHieu " +
                                               ", Nguon_VDN, Gia_Dinh_T, Ban_Than_T, Ngay_VDang, Ngay_CDCT, CVu_Dang_T " +
                                               ", CVu_DThe_T, Thang_Doan, Thang_CM, Thang_BC, Thang_NNgu, Thang_XNgu " +
                                               ", Thang_TNgu, NQuan_HT, NQuan_XP, TQuan_HT, TQuan_XP, Loai_No_T " +
                                               ", DTich_No, Nguon_Go_T, Dia_Chi, Loai_SKhoe, Benh_Chi_T, Thuong_T_T " +
                                               ", Huong_SD, Ly_Do_Vao, Ly_Do_Ra, Ngay_Vao, Ngay_Ra, Cap_Nhat_C " +
                                               ", Status, Ngach_Luong, Picture, Deleted, ChuyenRa " +
                                               ", UserID, DauMoi_ID, CreateDate) " +
                                    "VALUES (@DauMoiID, @Khoa, @So_Hieu_SQ, @So_Hieu_QN, @HoTen_KS " +
                                               ", @BiDanh, @Ho, @Dem, @Ten, @Ten_Khac, @Cap_Bac, @Thang_CBac " +
                                               ", @Lan_NLuong, @HeSoLuong, @Bac_Luong, @Muc_Luong, @LuongChinh, @Thang_NL " +
                                               ", @Chuc_Vu, @Thang_CVu, @Chuc_Kiem, @Dung_CVCT, @Loai_DV, @Don_Vi_CT " +
                                               ", @Khoi_CTac, @Ngay_Sinh, @Gioi_Tinh, @Binh_Chung, @Nganh_CTac, @Dan_Toc_T " +
                                               ", @Ton_Giao_T, @Loai_CBo, @Van_Hoa, @CHQL, @LLCT, @CMNV, @HocHam, @HocVi, @DanhHieu " +
                                               ", @Nguon_VDN, @Gia_Dinh_T, @Ban_Than_T, @Ngay_VDang, @Ngay_CDCT, @CVu_Dang_T " +
                                               ", @CVu_DThe_T, @Thang_Doan, @Thang_CM, @Thang_BC, @Thang_NNgu, @Thang_XNgu " +
                                               ", @Thang_TNgu, @NQuan_HT, @NQuan_XP, @TQuan_HT, @TQuan_XP, @Loai_No_T " +
                                               ", @DTich_No, @Nguon_Go_T, @Dia_Chi, @Loai_SKhoe, @Benh_Chi_T, @Thuong_T_T " +
                                               ", @Huong_SD, @Ly_Do_Vao, @Ly_Do_Ra, @Ngay_Vao, @Ngay_Ra, @Cap_Nhat_C " +
                                               ", @Status, @Ngach_Luong, @Picture, @Deleted, @ChuyenRa " +
                                               ", @UserID, @DauMoi_ID, GetDate()); ";


                #endregion SQLInsert

                foreach (DataRow dr in dtCanBo.Rows)
                {
                    //try
                    //{
                    #region sqlCanBo

                    lblTrangThai.Text = "Đang chuyển đổi hồ sơ cán bộ: " + dr["khoa"].ToString();

                    Application.DoEvents();




                    #region Parameters
                    arrParametersCanBo.Clear();
                    arrParametersCanBo.Add(SqlHelper.CreateParameterObject("@DauMoiID", SqlDbType.Int, ParameterDirection.Input, MyCommon.CurrentUserDauMoiID));

                    arrParametersCanBo.Add(SqlHelper.CreateParameterObject("@Khoa", SqlDbType.NVarChar, ParameterDirection.Input, MyCommon.CurrentUserDauMoiID + "_" + dr["Khoa"]));
                    arrParametersCanBo.Add(SqlHelper.CreateParameterObject("@So_Hieu_SQ", SqlDbType.NVarChar, ParameterDirection.Input, dr["So_Hieu_SQ"]));
                    arrParametersCanBo.Add(SqlHelper.CreateParameterObject("@So_Hieu_QN", SqlDbType.NVarChar, ParameterDirection.Input, dr["So_Hieu_QN"]));
                    arrParametersCanBo.Add(SqlHelper.CreateParameterObject("@HoTen_KS", SqlDbType.NVarChar, ParameterDirection.Input, Converter.TCVN3ToUnicode(dr["HoTen_KS"].ToString())));
                    arrParametersCanBo.Add(SqlHelper.CreateParameterObject("@BiDanh", SqlDbType.NVarChar, ParameterDirection.Input, Converter.TCVN3ToUnicode(dr["BiDanh"].ToString())));
                    arrParametersCanBo.Add(SqlHelper.CreateParameterObject("@Ho", SqlDbType.NVarChar, ParameterDirection.Input, Converter.TCVN3ToUnicode(dr["Ho"].ToString())));
                    arrParametersCanBo.Add(SqlHelper.CreateParameterObject("@Dem", SqlDbType.NVarChar, ParameterDirection.Input, Converter.TCVN3ToUnicode(dr["Dem"].ToString())));
                    arrParametersCanBo.Add(SqlHelper.CreateParameterObject("@Ten", SqlDbType.NVarChar, ParameterDirection.Input, Converter.TCVN3ToUnicode(dr["Ten"].ToString())));
                    arrParametersCanBo.Add(SqlHelper.CreateParameterObject("@Ten_Khac", SqlDbType.NVarChar, ParameterDirection.Input, Converter.TCVN3ToUnicode(dr["Ten_Khac"].ToString())));
                    arrParametersCanBo.Add(SqlHelper.CreateParameterObject("@Cap_Bac", SqlDbType.Int, ParameterDirection.Input, dr["Cap_Bac"]));
                    arrParametersCanBo.Add(SqlHelper.CreateParameterObject("@Thang_CBac", SqlDbType.DateTime, ParameterDirection.Input, Util.DATETIME.ToDateFromMMyyyy(dr["Thang_CBac"].ToString())));
                    arrParametersCanBo.Add(SqlHelper.CreateParameterObject("@Lan_NLuong", SqlDbType.Int, ParameterDirection.Input, Util.ToIntNull(dr["Lan_NLuong"])));
                    arrParametersCanBo.Add(SqlHelper.CreateParameterObject("@HeSoLuong", SqlDbType.Float, ParameterDirection.Input, dr["HeSoLuong"]));
                    arrParametersCanBo.Add(SqlHelper.CreateParameterObject("@Bac_Luong", SqlDbType.Float, ParameterDirection.Input, dr["Bac_Luong"]));
                    arrParametersCanBo.Add(SqlHelper.CreateParameterObject("@Muc_Luong", SqlDbType.Float, ParameterDirection.Input, dr["Muc_Luong"]));
                    arrParametersCanBo.Add(SqlHelper.CreateParameterObject("@LuongChinh", SqlDbType.Float, ParameterDirection.Input, 0));
                    arrParametersCanBo.Add(SqlHelper.CreateParameterObject("@Thang_NL", SqlDbType.DateTime, ParameterDirection.Input, Util.DATETIME.ToDateFromMMyyyy(dr["Thang_NL"].ToString())));
                    arrParametersCanBo.Add(SqlHelper.CreateParameterObject("@Chuc_Vu", SqlDbType.Int, ParameterDirection.Input, dr["Chuc_Vu"]));
                    arrParametersCanBo.Add(SqlHelper.CreateParameterObject("@Thang_CVu", SqlDbType.DateTime, ParameterDirection.Input, Util.DATETIME.ToDateFromMMyyyy(dr["Thang_CVu"].ToString())));
                    arrParametersCanBo.Add(SqlHelper.CreateParameterObject("@Chuc_Kiem", SqlDbType.NVarChar, ParameterDirection.Input, Converter.TCVN3ToUnicode(dr["Chuc_Kiem"].ToString())));
                    arrParametersCanBo.Add(SqlHelper.CreateParameterObject("@Dung_CVCT", SqlDbType.NVarChar, ParameterDirection.Input, ""));
                    arrParametersCanBo.Add(SqlHelper.CreateParameterObject("@Loai_DV", SqlDbType.Int, ParameterDirection.Input, null));
                    arrParametersCanBo.Add(SqlHelper.CreateParameterObject("@Don_Vi_CT", SqlDbType.Int, ParameterDirection.Input, dr["Don_Vi_CT"]));
                    arrParametersCanBo.Add(SqlHelper.CreateParameterObject("@Khoi_CTac", SqlDbType.Int, ParameterDirection.Input, dr["Khoi_CTac"]));
                    arrParametersCanBo.Add(SqlHelper.CreateParameterObject("@Ngay_Sinh", SqlDbType.DateTime, ParameterDirection.Input, Util.DATETIME.ParseNgaySinh(dr["Ngay_Sinh"].ToString())));
                    arrParametersCanBo.Add(SqlHelper.CreateParameterObject("@Gioi_Tinh", SqlDbType.NVarChar, ParameterDirection.Input, Converter.TCVN3ToUnicode(dr["Gioi_Tinh"].ToString())));
                    arrParametersCanBo.Add(SqlHelper.CreateParameterObject("@Binh_Chung", SqlDbType.Int, ParameterDirection.Input, dr["Binh_Chung"]));
                    arrParametersCanBo.Add(SqlHelper.CreateParameterObject("@Nganh_CTac", SqlDbType.Int, ParameterDirection.Input, dr["Nganh_CTac"]));
                    arrParametersCanBo.Add(SqlHelper.CreateParameterObject("@Dan_Toc_T", SqlDbType.NVarChar, ParameterDirection.Input, Converter.TCVN3ToUnicode(dr["Dan_Toc_T"].ToString())));
                    arrParametersCanBo.Add(SqlHelper.CreateParameterObject("@Ton_Giao_T", SqlDbType.NVarChar, ParameterDirection.Input, Converter.TCVN3ToUnicode(dr["Ton_Giao_T"].ToString())));
                    arrParametersCanBo.Add(SqlHelper.CreateParameterObject("@Loai_CBo", SqlDbType.Int, ParameterDirection.Input, dr["Loai_CBo"]));
                    arrParametersCanBo.Add(SqlHelper.CreateParameterObject("@Van_Hoa", SqlDbType.Int, ParameterDirection.Input, dr["Van_Hoa"]));
                    arrParametersCanBo.Add(SqlHelper.CreateParameterObject("@CHQL", SqlDbType.NVarChar, ParameterDirection.Input, Converter.TCVN3ToUnicode(dr["CHQL"].ToString())));
                    arrParametersCanBo.Add(SqlHelper.CreateParameterObject("@LLCT", SqlDbType.NVarChar, ParameterDirection.Input, Converter.TCVN3ToUnicode(dr["LLCT"].ToString())));
                    arrParametersCanBo.Add(SqlHelper.CreateParameterObject("@CMNV", SqlDbType.NVarChar, ParameterDirection.Input, Converter.TCVN3ToUnicode(dr["CMNV"].ToString())));
                    arrParametersCanBo.Add(SqlHelper.CreateParameterObject("@HocHam", SqlDbType.Int, ParameterDirection.Input, dr["HocHam"]));
                    arrParametersCanBo.Add(SqlHelper.CreateParameterObject("@HocVi", SqlDbType.Int, ParameterDirection.Input, dr["HocVi"]));
                    arrParametersCanBo.Add(SqlHelper.CreateParameterObject("@DanhHieu", SqlDbType.NVarChar, ParameterDirection.Input, Converter.TCVN3ToUnicode(dr["DanhHieu"].ToString())));
                    arrParametersCanBo.Add(SqlHelper.CreateParameterObject("@Nguon_VDN", SqlDbType.Int, ParameterDirection.Input, dr["Nguon_VDN"]));
                    arrParametersCanBo.Add(SqlHelper.CreateParameterObject("@Gia_Dinh_T", SqlDbType.NVarChar, ParameterDirection.Input, Converter.TCVN3ToUnicode(dr["Gia_Dinh_T"].ToString())));
                    arrParametersCanBo.Add(SqlHelper.CreateParameterObject("@Ban_Than_T", SqlDbType.NVarChar, ParameterDirection.Input, Converter.TCVN3ToUnicode(dr["Ban_Than_T"].ToString())));
                    arrParametersCanBo.Add(SqlHelper.CreateParameterObject("@Ngay_VDang", SqlDbType.DateTime, ParameterDirection.Input, Util.DATETIME.ToDateFromMMyyyy(dr["Ngay_VDang"].ToString())));
                    arrParametersCanBo.Add(SqlHelper.CreateParameterObject("@Ngay_CDCT", SqlDbType.DateTime, ParameterDirection.Input, Util.DATETIME.ToDateFromMMyyyy(dr["Ngay_CDCT"].ToString())));
                    arrParametersCanBo.Add(SqlHelper.CreateParameterObject("@CVu_Dang_T", SqlDbType.NVarChar, ParameterDirection.Input, Converter.TCVN3ToUnicode(dr["CVu_Dang_T"].ToString())));
                    arrParametersCanBo.Add(SqlHelper.CreateParameterObject("@CVu_DThe_T", SqlDbType.NVarChar, ParameterDirection.Input, Converter.TCVN3ToUnicode(dr["CVu_DThe_T"].ToString())));
                    arrParametersCanBo.Add(SqlHelper.CreateParameterObject("@Thang_Doan", SqlDbType.DateTime, ParameterDirection.Input, Util.DATETIME.ToDateFromMMyyyy(dr["Thang_Doan"].ToString())));
                    arrParametersCanBo.Add(SqlHelper.CreateParameterObject("@Thang_CM", SqlDbType.DateTime, ParameterDirection.Input, Util.DATETIME.ToDateFromMMyyyy(dr["Thang_CM"].ToString())));
                    arrParametersCanBo.Add(SqlHelper.CreateParameterObject("@Thang_BC", SqlDbType.DateTime, ParameterDirection.Input, Util.DATETIME.ToDateFromMMyyyy(dr["Thang_BC"].ToString())));
                    arrParametersCanBo.Add(SqlHelper.CreateParameterObject("@Thang_NNgu", SqlDbType.DateTime, ParameterDirection.Input, Util.DATETIME.ToDateFromMMyyyy(dr["Thang_NNgu"].ToString())));
                    arrParametersCanBo.Add(SqlHelper.CreateParameterObject("@Thang_XNgu", SqlDbType.DateTime, ParameterDirection.Input, Util.DATETIME.ToDateFromMMyyyy(dr["Thang_XNgu"].ToString())));
                    arrParametersCanBo.Add(SqlHelper.CreateParameterObject("@Thang_TNgu", SqlDbType.DateTime, ParameterDirection.Input, Util.DATETIME.ToDateFromMMyyyy(dr["Thang_TNgu"].ToString())));
                    arrParametersCanBo.Add(SqlHelper.CreateParameterObject("@NQuan_HT", SqlDbType.Int, ParameterDirection.Input, dr["NQuan_HT"]));
                    arrParametersCanBo.Add(SqlHelper.CreateParameterObject("@NQuan_XP", SqlDbType.NVarChar, ParameterDirection.Input, Converter.TCVN3ToUnicode(dr["NQuan_XP"].ToString())));
                    arrParametersCanBo.Add(SqlHelper.CreateParameterObject("@TQuan_HT", SqlDbType.Int, ParameterDirection.Input, dr["TQuan_HT"]));
                    arrParametersCanBo.Add(SqlHelper.CreateParameterObject("@TQuan_XP", SqlDbType.NVarChar, ParameterDirection.Input, Converter.TCVN3ToUnicode(dr["TQuan_XP"].ToString())));
                    arrParametersCanBo.Add(SqlHelper.CreateParameterObject("@Loai_No_T", SqlDbType.NVarChar, ParameterDirection.Input, Converter.TCVN3ToUnicode(dr["Loai_No_T"].ToString())));
                    arrParametersCanBo.Add(SqlHelper.CreateParameterObject("@DTich_No", SqlDbType.Float, ParameterDirection.Input, dr["DTich_No"]));
                    arrParametersCanBo.Add(SqlHelper.CreateParameterObject("@Nguon_Go_T", SqlDbType.NVarChar, ParameterDirection.Input, Converter.TCVN3ToUnicode(dr["Nguon_Go_T"].ToString())));
                    arrParametersCanBo.Add(SqlHelper.CreateParameterObject("@Dia_Chi", SqlDbType.NVarChar, ParameterDirection.Input, Converter.TCVN3ToUnicode(dr["Dia_Chi"].ToString())));
                    arrParametersCanBo.Add(SqlHelper.CreateParameterObject("@Loai_SKhoe", SqlDbType.Int, ParameterDirection.Input, dr["Loai_SKhoe"]));
                    arrParametersCanBo.Add(SqlHelper.CreateParameterObject("@Benh_Chi_T", SqlDbType.NVarChar, ParameterDirection.Input, Converter.TCVN3ToUnicode(dr["Benh_Chi_T"].ToString())));
                    arrParametersCanBo.Add(SqlHelper.CreateParameterObject("@Thuong_T_T", SqlDbType.NVarChar, ParameterDirection.Input, Converter.TCVN3ToUnicode(dr["Thuong_T_T"].ToString())));
                    arrParametersCanBo.Add(SqlHelper.CreateParameterObject("@Huong_SD", SqlDbType.Int, ParameterDirection.Input, dr["Huong_SD"]));
                    arrParametersCanBo.Add(SqlHelper.CreateParameterObject("@Ly_Do_Vao", SqlDbType.Int, ParameterDirection.Input, dr["Ly_Do_Vao"]));
                    arrParametersCanBo.Add(SqlHelper.CreateParameterObject("@Ly_Do_Ra", SqlDbType.Int, ParameterDirection.Input, dr["Ly_Do_Ra"]));
                    arrParametersCanBo.Add(SqlHelper.CreateParameterObject("@Ngay_Vao", SqlDbType.DateTime, ParameterDirection.Input, dr["Ngay_Vao"]));
                    arrParametersCanBo.Add(SqlHelper.CreateParameterObject("@Ngay_Ra", SqlDbType.DateTime, ParameterDirection.Input, dr["Ngay_Ra"]));
                    arrParametersCanBo.Add(SqlHelper.CreateParameterObject("@Cap_Nhat_C", SqlDbType.NVarChar, ParameterDirection.Input, ""));

                    arrParametersCanBo.Add(SqlHelper.CreateParameterObject("@Status", SqlDbType.NVarChar, ParameterDirection.Input, ""));
                    arrParametersCanBo.Add(SqlHelper.CreateParameterObject("@Ngach_Luong", SqlDbType.NVarChar, ParameterDirection.Input, Converter.TCVN3ToUnicode(dr["Ngach_Luong"].ToString())));


                    arrParametersCanBo.Add(SqlHelper.CreateParameterObject("@Picture", SqlDbType.Image, ParameterDirection.Input, dr["Picture"]));

                    arrParametersCanBo.Add(SqlHelper.CreateParameterObject("@Deleted", SqlDbType.Bit, ParameterDirection.Input, false));
                    arrParametersCanBo.Add(SqlHelper.CreateParameterObject("@ChuyenRa", SqlDbType.Bit, ParameterDirection.Input, false));
                    arrParametersCanBo.Add(SqlHelper.CreateParameterObject("@UserID", SqlDbType.Int, ParameterDirection.Input, MyCommon.CurrentUserID));
                    arrParametersCanBo.Add(SqlHelper.CreateParameterObject("@DauMoi_ID", SqlDbType.Int, ParameterDirection.Input, MyCommon.CurrentUserDauMoiID));

                    #endregion Parameters


                    SqlHelper.ExecuteNonQuery(CommandType.Text, sqlCanBo, arrParametersCanBo);

                    #endregion sqlCanBo

                    //}
                    //catch (Exception _ex)
                    //{
                    //    throw _ex;
                    //}
                }
                arrParametersCanBo = new List<SqlParameter>();
                arrParametersCanBo.Add(SqlHelper.CreateParameterObject("@DauMoiID", SqlDbType.Int, ParameterDirection.Input, MyCommon.CurrentUserDauMoiID));

                maxKhoa = Util.ToInt(SqlHelper.ExecuteScalar(CommandType.Text, "Select Max(Khoa) From tblCanBo Where DauMoiID=@DauMoiID ", arrParametersCanBo));

                sqlCanBo = "Update tblDau_Moi Set CurentID=" + maxKhoa + " Where ID=@DauMoiID ";
                SqlHelper.ExecuteNonQuery(CommandType.Text, sqlCanBo, arrParametersCanBo);
                #endregion CanBo

                #region TrichNgang

                DataTable dtTrichNgang = SqlHelper_Convert.ExecuteDataTable(CommandType.Text, "Select * From tb_TrichNgang ");
                List<SqlParameter> arrParametersTrichNgang = new List<SqlParameter>();


                #region SQLInsert
                string sqlTrichNgang = "Insert Into tblTrichNgang(Khoa, DauMoiID, Ngay_HH, Ngay_HV, Di_NN, Truoc_CM, KTCT_BT, KTCT_VC, Nhan_Xet, So_ACE, So_AET, So_ACE_VC, So_AET_VC, Thu_May, Thu_May_VC, Ma_Gia_Dinh_VC, Ma_Ban_Than_VC, Que_Quan_XPVC, Tru_Quan_XPVC, Que_Quan_HTVC, Tru_Quan_HTVC, Ghi_Them, Ngay_Trich, Can_Cu_Trich, UserID, CreateDate) " +
                           "Values(@Khoa, @DauMoiID, @Ngay_HH, @Ngay_HV, @Di_NN, @Truoc_CM, @KTCT_BT, @KTCT_VC, @Nhan_Xet, @So_ACE, @So_AET, @So_ACE_VC, @So_AET_VC, @Thu_May, @Thu_May_VC, @Ma_Gia_Dinh_VC, @Ma_Ban_Than_VC, @Que_Quan_XPVC, @Tru_Quan_XPVC, @Que_Quan_HTVC, @Tru_Quan_HTVC, @Ghi_Them, @Ngay_Trich, @Can_Cu_Trich, @UserID, GetDate()) ";

                #endregion SQLInsert

                foreach (DataRow dr in dtTrichNgang.Rows)
                {
                    #region sqlTrichNgang

                    lblTrangThai.Text = "Đang chuyển đổi hồ sơ trích ngang: " + dr["Khoa"].ToString();

                    Application.DoEvents();




                    #region AddParameters
                    arrParametersTrichNgang.Clear();

                    arrParametersTrichNgang.Add(SqlHelper.CreateParameterObject("@Khoa", SqlDbType.NVarChar, ParameterDirection.Input, MyCommon.CurrentUserDauMoiID + "_" + dr["Khoa"]));
                    arrParametersTrichNgang.Add(SqlHelper.CreateParameterObject("@DauMoiID", SqlDbType.Int, ParameterDirection.Input, MyCommon.CurrentUserDauMoiID));
                    arrParametersTrichNgang.Add(SqlHelper.CreateParameterObject("@Ngay_HH", SqlDbType.DateTime, ParameterDirection.Input, null));
                    arrParametersTrichNgang.Add(SqlHelper.CreateParameterObject("@Ngay_HV", SqlDbType.DateTime, ParameterDirection.Input, null));
                    arrParametersTrichNgang.Add(SqlHelper.CreateParameterObject("@Di_NN", SqlDbType.NVarChar, ParameterDirection.Input, Converter.TCVN3ToUnicode(dr["Di_NN"].ToString())));
                    arrParametersTrichNgang.Add(SqlHelper.CreateParameterObject("@Truoc_CM", SqlDbType.NVarChar, ParameterDirection.Input, Converter.TCVN3ToUnicode(dr["Truoc_CM"].ToString())));
                    arrParametersTrichNgang.Add(SqlHelper.CreateParameterObject("@KTCT_BT", SqlDbType.NVarChar, ParameterDirection.Input, Converter.TCVN3ToUnicode(dr["KTCT_BT"].ToString())));

                    arrParametersTrichNgang.Add(SqlHelper.CreateParameterObject("@KTCT_VC", SqlDbType.NVarChar, ParameterDirection.Input, Converter.TCVN3ToUnicode(dr["KTCT_VC"].ToString())));
                    arrParametersTrichNgang.Add(SqlHelper.CreateParameterObject("@Nhan_Xet", SqlDbType.NVarChar, ParameterDirection.Input, Converter.TCVN3ToUnicode(dr["Nhan_Xet"].ToString())));
                    arrParametersTrichNgang.Add(SqlHelper.CreateParameterObject("@So_ACE", SqlDbType.Int, ParameterDirection.Input, dr["So_ACE"]));
                    arrParametersTrichNgang.Add(SqlHelper.CreateParameterObject("@So_AET", SqlDbType.Int, ParameterDirection.Input, dr["So_AET"]));
                    arrParametersTrichNgang.Add(SqlHelper.CreateParameterObject("@So_ACE_VC", SqlDbType.Int, ParameterDirection.Input, dr["So_ACE_VC"]));
                    arrParametersTrichNgang.Add(SqlHelper.CreateParameterObject("@So_AET_VC", SqlDbType.Int, ParameterDirection.Input, dr["So_AET_VC"]));
                    arrParametersTrichNgang.Add(SqlHelper.CreateParameterObject("@Thu_May", SqlDbType.Int, ParameterDirection.Input, dr["Thu_May"]));
                    arrParametersTrichNgang.Add(SqlHelper.CreateParameterObject("@Thu_May_VC", SqlDbType.Int, ParameterDirection.Input, dr["Thu_May_VC"]));
                    arrParametersTrichNgang.Add(SqlHelper.CreateParameterObject("@Ma_Gia_Dinh_VC", SqlDbType.Int, ParameterDirection.Input, dr["Ma_Gia_Dinh_VC"]));
                    arrParametersTrichNgang.Add(SqlHelper.CreateParameterObject("@Ma_Ban_Than_VC", SqlDbType.Int, ParameterDirection.Input, dr["Ma_Ban_Than_VC"]));
                    arrParametersTrichNgang.Add(SqlHelper.CreateParameterObject("@Que_Quan_XPVC", SqlDbType.NVarChar, ParameterDirection.Input, Converter.TCVN3ToUnicode(dr["Que_Quan_XPVC"].ToString())));
                    arrParametersTrichNgang.Add(SqlHelper.CreateParameterObject("@Tru_Quan_XPVC", SqlDbType.NVarChar, ParameterDirection.Input, Converter.TCVN3ToUnicode(dr["Tru_Quan_XPVC"].ToString())));
                    arrParametersTrichNgang.Add(SqlHelper.CreateParameterObject("@Que_Quan_HTVC", SqlDbType.NVarChar, ParameterDirection.Input, Converter.TCVN3ToUnicode(dr["Que_Quan_HTVC"].ToString())));
                    arrParametersTrichNgang.Add(SqlHelper.CreateParameterObject("@Tru_Quan_HTVC", SqlDbType.NVarChar, ParameterDirection.Input, Converter.TCVN3ToUnicode(dr["Tru_Quan_HTVC"].ToString())));
                    arrParametersTrichNgang.Add(SqlHelper.CreateParameterObject("@Ghi_Them", SqlDbType.NVarChar, ParameterDirection.Input, ""));

                    arrParametersTrichNgang.Add(SqlHelper.CreateParameterObject("@Ngay_Trich", SqlDbType.DateTime, ParameterDirection.Input, null));
                    arrParametersTrichNgang.Add(SqlHelper.CreateParameterObject("@Can_Cu_Trich", SqlDbType.NVarChar, ParameterDirection.Input, ""));
                    arrParametersTrichNgang.Add(SqlHelper.CreateParameterObject("@UserID", SqlDbType.NVarChar, ParameterDirection.Input, MyCommon.CurrentUserID));

                    #endregion AddParameters


                    SqlHelper.ExecuteNonQuery(CommandType.Text, sqlTrichNgang, arrParametersTrichNgang);

                    #endregion sqlTrichNgang

                }

                #endregion TrichNgang

                #region Khac

                DataTable dtKhac = SqlHelper_Convert.ExecuteDataTable(CommandType.Text, "Select * From Khac ");
                List<SqlParameter> arrParametersKhac = new List<SqlParameter>();

                string sqlKhac = "";

                #region SQLInsert
                sqlKhac = "Insert Into tblKhac(ID, Khoa, DauMoiID, Thang_SK, Noi_Dung, UserID, CreateDate) " +
                                "Values(@ID, @Khoa, @DauMoiID, @Thang_SK, @Noi_Dung, @UserID, GetDate()) ";

                #endregion SQLInsert

                foreach (DataRow dr in dtKhac.Rows)
                {
                    #region sqlKhac

                    lblTrangThai.Text = "Đang chuyển đổi hồ sơ khác của cán bộ: " + dr["ID"].ToString();

                    Application.DoEvents();





                    #region AddParameters
                    arrParametersKhac.Clear();

                    arrParametersKhac.Add(SqlHelper.CreateParameterObject("@Khoa", SqlDbType.NVarChar, ParameterDirection.Input, MyCommon.CurrentUserDauMoiID + "_" + dr["Khoa"]));
                    arrParametersKhac.Add(SqlHelper.CreateParameterObject("@DauMoiID", SqlDbType.Int, ParameterDirection.Input, MyCommon.CurrentUserDauMoiID));
                    arrParametersKhac.Add(SqlHelper.CreateParameterObject("@ID", SqlDbType.Int, ParameterDirection.Input, dr["ID"]));

                    arrParametersKhac.Add(SqlHelper.CreateParameterObject("@Thang_SK", SqlDbType.DateTime, ParameterDirection.Input, Util.DATETIME.ToDateFromMMyyyy(dr["Thang_SK"].ToString())));
                    arrParametersKhac.Add(SqlHelper.CreateParameterObject("@Noi_Dung", SqlDbType.NVarChar, ParameterDirection.Input, Converter.TCVN3ToUnicode(dr["Noi_Dung"].ToString())));
                    arrParametersKhac.Add(SqlHelper.CreateParameterObject("@UserID", SqlDbType.Int, ParameterDirection.Input, MyCommon.CurrentUserID));

                    #endregion AddParameters


                    SqlHelper.ExecuteNonQuery(CommandType.Text, sqlKhac, arrParametersKhac);

                    #endregion sqlKhac

                }

                #endregion Khac

                #region QT_CD

                DataTable dtQT_CD = SqlHelper_Convert.ExecuteDataTable(CommandType.Text, "Select * From QT_CD ");
                List<SqlParameter> arrParametersQT_CD = new List<SqlParameter>();

                string sqlQT_CD = "";

                #region SQLInsert
                sqlQT_CD = "Insert Into tblQT_CD(ID, Khoa, DauMoiID, Ch_Truong, Bat_Dau, Ket_Thuc, CVi_ChDau, Don_Vi, UserID, CreateDate) " +
                                "Values(@ID, @Khoa, @DauMoiID, @Ch_Truong, @Bat_Dau, @Ket_Thuc, @CVi_ChDau, @Don_Vi, @UserID, GetDate()); ";

                #endregion SQLInsert

                foreach (DataRow dr in dtQT_CD.Rows)
                {
                    lblTrangThai.Text = "Đang cập nhật QT_CD: " + dr["Khoa"].ToString();

                    Application.DoEvents();
                    //if (!CheckExitsCB(dr["Khoa"].ToString()))
                    //    continue;

                    #region sqlQT_CD


                    #region AddParameters
                    arrParametersQT_CD.Clear();
                    arrParametersQT_CD.Add(SqlHelper.CreateParameterObject("@Khoa", SqlDbType.NVarChar, ParameterDirection.Input, MyCommon.CurrentUserDauMoiID + "_" + dr["Khoa"]));
                    arrParametersQT_CD.Add(SqlHelper.CreateParameterObject("@DauMoiID", SqlDbType.Int, ParameterDirection.Input, MyCommon.CurrentUserDauMoiID));
                    arrParametersQT_CD.Add(SqlHelper.CreateParameterObject("@ID", SqlDbType.Int, ParameterDirection.Input, dr["ID"]));
                    arrParametersQT_CD.Add(SqlHelper.CreateParameterObject("@Ch_Truong", SqlDbType.Int, ParameterDirection.Input, dr["Ch_Truong"]));
                    arrParametersQT_CD.Add(SqlHelper.CreateParameterObject("@Bat_Dau", SqlDbType.DateTime, ParameterDirection.Input, Util.DATETIME.ToDateFromMMyyyy(dr["Bat_Dau"].ToString())));

                    arrParametersQT_CD.Add(SqlHelper.CreateParameterObject("@Ket_Thuc", SqlDbType.DateTime, ParameterDirection.Input, Util.DATETIME.ToDateFromMMyyyy(dr["Ket_Thuc"].ToString())));
                    arrParametersQT_CD.Add(SqlHelper.CreateParameterObject("@CVi_ChDau", SqlDbType.Int, ParameterDirection.Input, dr["CVi_ChDau"]));
                    arrParametersQT_CD.Add(SqlHelper.CreateParameterObject("@Don_Vi", SqlDbType.NVarChar, ParameterDirection.Input, Converter.TCVN3ToUnicode(dr["Don_Vi"].ToString())));
                    arrParametersQT_CD.Add(SqlHelper.CreateParameterObject("@UserID", SqlDbType.Int, ParameterDirection.Input, MyCommon.CurrentUserID));

                    #endregion AddParameters


                    SqlHelper.ExecuteNonQuery(CommandType.Text, sqlQT_CD, arrParametersQT_CD);

                    #endregion sqlQT_CD

                }

                #endregion QT_CD

                #region QT_CT

                DataTable dtQT_CT = SqlHelper_Convert.ExecuteDataTable(CommandType.Text, "Select * From QT_CT ");
                List<SqlParameter> arrParametersQT_CT = new List<SqlParameter>();

                string sqlQT_CT = "";

                #region SQLInsert
                sqlQT_CT = "Insert Into tblQT_CT(ID, Khoa, DauMoiID, Tu, Den, Chuc_T, Chuc, DonVi_T, DonVi, Cap_T, Cap, TG_Cap, Dang, TG_Dang, UserID, CreateDate) " +
                                "Values(@ID, @Khoa, @DauMoiID, @Tu, @Den, @Chuc_T, @Chuc, @DonVi_T, @DonVi, @Cap_T, @Cap, @TG_Cap, @Dang, @TG_Dang, @UserID, GetDate()) ";

                #endregion SQLInsert

                int i = 0;
                while (i < dtQT_CT.Rows.Count)

                // for (int i = 0; i < dtQT_CT.Rows.Count; i++ )
                {
                    lblTrangThai.Text = "Đang cập nhật QT_CT: " + dtQT_CT.Rows[i]["Khoa"].ToString();

                    Application.DoEvents();
                    //if (!CheckExitsCB(dtQT_CT.Rows[i]["Khoa"].ToString()))
                    //    continue;
                    #region sqlQT_CT


                    #region AddParameters
                    arrParametersQT_CT.Clear();
                    arrParametersQT_CT.Add(SqlHelper.CreateParameterObject("@Khoa", SqlDbType.NVarChar, ParameterDirection.Input, MyCommon.CurrentUserDauMoiID + "_" + dtQT_CT.Rows[i]["Khoa"]));
                    arrParametersQT_CT.Add(SqlHelper.CreateParameterObject("@DauMoiID", SqlDbType.Int, ParameterDirection.Input, MyCommon.CurrentUserDauMoiID));
                    arrParametersQT_CT.Add(SqlHelper.CreateParameterObject("@ID", SqlDbType.Int, ParameterDirection.Input, dtQT_CT.Rows[i]["ID"]));
                    arrParametersQT_CT.Add(SqlHelper.CreateParameterObject("@Tu", SqlDbType.DateTime, ParameterDirection.Input, Util.DATETIME.ToDateFromMMyyyy(dtQT_CT.Rows[i]["Tu"].ToString())));
                    arrParametersQT_CT.Add(SqlHelper.CreateParameterObject("@Den", SqlDbType.DateTime, ParameterDirection.Input, Util.DATETIME.ToDateFromMMyyyy(dtQT_CT.Rows[i]["Den"].ToString())));

                    arrParametersQT_CT.Add(SqlHelper.CreateParameterObject("@Chuc_T", SqlDbType.NVarChar, ParameterDirection.Input, Converter.TCVN3ToUnicode(dtQT_CT.Rows[i]["Chuc_T"].ToString())));
                    arrParametersQT_CT.Add(SqlHelper.CreateParameterObject("@Chuc", SqlDbType.Int, ParameterDirection.Input, dtQT_CT.Rows[i]["Chuc"]));
                    arrParametersQT_CT.Add(SqlHelper.CreateParameterObject("@DonVi_T", SqlDbType.NVarChar, ParameterDirection.Input, Converter.TCVN3ToUnicode(dtQT_CT.Rows[i]["DonVi_T"].ToString())));
                    arrParametersQT_CT.Add(SqlHelper.CreateParameterObject("@DonVi", SqlDbType.Int, ParameterDirection.Input, dtQT_CT.Rows[i]["DonVi"]));

                    arrParametersQT_CT.Add(SqlHelper.CreateParameterObject("@Cap_T", SqlDbType.NVarChar, ParameterDirection.Input, Converter.TCVN3ToUnicode(dtQT_CT.Rows[i]["Cap_T"].ToString())));
                    arrParametersQT_CT.Add(SqlHelper.CreateParameterObject("@Cap", SqlDbType.Int, ParameterDirection.Input, dtQT_CT.Rows[i]["Cap"]));
                    arrParametersQT_CT.Add(SqlHelper.CreateParameterObject("@TG_Cap", SqlDbType.DateTime, ParameterDirection.Input, Util.DATETIME.ToDateFromMMyyyy(dtQT_CT.Rows[i]["TG_Cap"].ToString())));
                    arrParametersQT_CT.Add(SqlHelper.CreateParameterObject("@Dang", SqlDbType.NVarChar, ParameterDirection.Input, Converter.TCVN3ToUnicode(dtQT_CT.Rows[i]["Dang"].ToString())));
                    arrParametersQT_CT.Add(SqlHelper.CreateParameterObject("@TG_Dang", SqlDbType.DateTime, ParameterDirection.Input, Util.DATETIME.ToDateFromMMyyyy(dtQT_CT.Rows[i]["TG_Dang"].ToString())));
                    arrParametersQT_CT.Add(SqlHelper.CreateParameterObject("@UserID", SqlDbType.Int, ParameterDirection.Input, MyCommon.CurrentUserID));

                    #endregion AddParameters


                    SqlHelper.ExecuteNonQuery(CommandType.Text, sqlQT_CT, arrParametersQT_CT);

                    #endregion sqlQT_CT
                    i++;
                }

                #endregion QT_CT

                #region QT_DG

                DataTable dtQT_DG = SqlHelper_Convert.ExecuteDataTable(CommandType.Text, "Select * From QT_DG ");
                List<SqlParameter> arrParametersQT_DG = new List<SqlParameter>();

                string sqlQT_DG = "";

                #region SQLInsert
                sqlQT_DG = "Insert Into tblQT_DG(ID, Khoa, DauMoiID, SKien_DGia, Thang_SK, NDung_SK, Ghi_Chu, UserID, CreateDate) " +
                                "Values(@ID, @Khoa, @DauMoiID, @SKien_DGia, @Thang_SK, @NDung_SK, @Ghi_Chu, @UserID, GetDate()) ";

                #endregion SQLInsert

                foreach (DataRow dr in dtQT_DG.Rows)
                {
                    lblTrangThai.Text = "Đang cập nhật QT_DG: " + dr["Khoa"].ToString();

                    Application.DoEvents();
                    //if (!CheckExitsCB(dr["Khoa"].ToString()))
                    //    continue;

                    #region sqlQT_DG


                    #region AddParameters
                    arrParametersQT_DG.Clear();
                    arrParametersQT_DG.Add(SqlHelper.CreateParameterObject("@Khoa", SqlDbType.NVarChar, ParameterDirection.Input, MyCommon.CurrentUserDauMoiID + "_" + dr["Khoa"]));
                    arrParametersQT_DG.Add(SqlHelper.CreateParameterObject("@DauMoiID", SqlDbType.Int, ParameterDirection.Input, MyCommon.CurrentUserDauMoiID));
                    arrParametersQT_DG.Add(SqlHelper.CreateParameterObject("@ID", SqlDbType.Int, ParameterDirection.Input, dr["ID"]));

                    arrParametersQT_DG.Add(SqlHelper.CreateParameterObject("@SKien_DGia", SqlDbType.Int, ParameterDirection.Input, dr["SKien_DGia"]));
                    arrParametersQT_DG.Add(SqlHelper.CreateParameterObject("@Thang_SK", SqlDbType.DateTime, ParameterDirection.Input, Util.DATETIME.ToDateFromMMyyyy(dr["Thang_SK"].ToString())));
                    arrParametersQT_DG.Add(SqlHelper.CreateParameterObject("@NDung_SK", SqlDbType.NVarChar, ParameterDirection.Input, Converter.TCVN3ToUnicode(dr["NDung_SK"].ToString())));
                    arrParametersQT_DG.Add(SqlHelper.CreateParameterObject("@Ghi_Chu", SqlDbType.NVarChar, ParameterDirection.Input, Converter.TCVN3ToUnicode(dr["Ghi_Chu"].ToString())));
                    arrParametersQT_DG.Add(SqlHelper.CreateParameterObject("@UserID", SqlDbType.Int, ParameterDirection.Input, MyCommon.CurrentUserID));

                    #endregion AddParameters


                    SqlHelper.ExecuteNonQuery(CommandType.Text, sqlQT_DG, arrParametersQT_DG);

                    #endregion sqlQT_DG

                }

                #endregion QT_DG

                #region QT_DT

                DataTable dtQT_DT = SqlHelper_Convert.ExecuteDataTable(CommandType.Text, "Select * From QT_DT ");
                List<SqlParameter> arrParametersQT_DT = new List<SqlParameter>();

                string sqlQT_DT = "";

                #region SQLInsert
                sqlQT_DT = "Insert Into tblQT_DT(ID, Khoa, DauMoiID, Loai_Hinh, Cap_Hoc, Ten_Nuoc, Ten_Co_So, CNganh_DT, Thang_BD, Thang_KT, Loai_TN_T, Bang_Cap, Luan_An, Dung_CNCT, UserID, CreateDate) " +
                                "Values(@ID, @Khoa, @DauMoiID, @Loai_Hinh, @Cap_Hoc, @Ten_Nuoc, @Ten_Co_So, @CNganh_DT, @Thang_BD, @Thang_KT, @Loai_TN_T, @Bang_Cap, @Luan_An, @Dung_CNCT, @UserID, GetDate()) ";

                #endregion SQLInsert

                foreach (DataRow dr in dtQT_DT.Rows)
                {
                    lblTrangThai.Text = "Đang cập nhật QT_DT: " + dr["Khoa"].ToString();

                    Application.DoEvents();
                    //if (!CheckExitsCB(dr["Khoa"].ToString()))
                    //    continue;
                    #region sqlQT_DT


                    #region AddParameters
                    arrParametersQT_DT.Clear();
                    arrParametersQT_DT.Add(SqlHelper.CreateParameterObject("@Khoa", SqlDbType.NVarChar, ParameterDirection.Input, MyCommon.CurrentUserDauMoiID + "_" + dr["Khoa"]));
                    arrParametersQT_DT.Add(SqlHelper.CreateParameterObject("@DauMoiID", SqlDbType.Int, ParameterDirection.Input, MyCommon.CurrentUserDauMoiID));
                    arrParametersQT_DT.Add(SqlHelper.CreateParameterObject("@ID", SqlDbType.Int, ParameterDirection.Input, dr["ID"]));

                    arrParametersQT_DT.Add(SqlHelper.CreateParameterObject("@Loai_Hinh", SqlDbType.Int, ParameterDirection.Input, dr["Loai_Hinh"]));
                    arrParametersQT_DT.Add(SqlHelper.CreateParameterObject("@Cap_Hoc", SqlDbType.Int, ParameterDirection.Input, dr["Cap_Hoc"]));
                    arrParametersQT_DT.Add(SqlHelper.CreateParameterObject("@Ten_Nuoc", SqlDbType.Int, ParameterDirection.Input, dr["Ten_Nuoc"]));
                    arrParametersQT_DT.Add(SqlHelper.CreateParameterObject("@Ten_Co_So", SqlDbType.Int, ParameterDirection.Input, dr["Ten_Co_So"]));
                    arrParametersQT_DT.Add(SqlHelper.CreateParameterObject("@CNganh_DT", SqlDbType.Int, ParameterDirection.Input, dr["CNganh_DT"]));
                    arrParametersQT_DT.Add(SqlHelper.CreateParameterObject("@Thang_BD", SqlDbType.DateTime, ParameterDirection.Input, Util.DATETIME.ToDateFromMMyyyy(dr["Thang_BD"].ToString())));
                    arrParametersQT_DT.Add(SqlHelper.CreateParameterObject("@Thang_KT", SqlDbType.DateTime, ParameterDirection.Input, Util.DATETIME.ToDateFromMMyyyy(dr["Thang_KT"].ToString())));
                    arrParametersQT_DT.Add(SqlHelper.CreateParameterObject("@Loai_TN_T", SqlDbType.NVarChar, ParameterDirection.Input, Converter.TCVN3ToUnicode(dr["Loai_TN_T"].ToString())));
                    arrParametersQT_DT.Add(SqlHelper.CreateParameterObject("@Bang_Cap", SqlDbType.NVarChar, ParameterDirection.Input, Converter.TCVN3ToUnicode(dr["Bang_Cap"].ToString())));
                    arrParametersQT_DT.Add(SqlHelper.CreateParameterObject("@Luan_An", SqlDbType.NVarChar, ParameterDirection.Input, Converter.TCVN3ToUnicode(dr["Luan_An"].ToString())));
                    arrParametersQT_DT.Add(SqlHelper.CreateParameterObject("@Dung_CNCT", SqlDbType.Bit, ParameterDirection.Input, 0));
                    arrParametersQT_DT.Add(SqlHelper.CreateParameterObject("@UserID", SqlDbType.Int, ParameterDirection.Input, MyCommon.CurrentUserID));

                    #endregion AddParameters


                    SqlHelper.ExecuteNonQuery(CommandType.Text, sqlQT_DT, arrParametersQT_DT);

                    #endregion sqlQT_DT

                }

                #endregion QT_DT



                #region Tieng

                DataTable dtTieng = SqlHelper_Convert.ExecuteDataTable(CommandType.Text, "Select * From Tieng ");
                List<SqlParameter> arrParametersTieng = new List<SqlParameter>();

                string sqlTieng = "";

                #region SQLInsert
                sqlTieng = "Insert Into tblTieng(ID, Khoa, DauMoiID, Loai, NgonNgu_T, Ma_NNgu, Ma_DToc, TrinhDo, ThoiGian, UserID, CreateDate) " +
                                "Values(@ID, @Khoa, @DauMoiID, @Loai, @NgonNgu_T, @Ma_NNgu, @Ma_DToc, @TrinhDo, @ThoiGian, @UserID, GetDate()); ";

                #endregion SQLInsert

                foreach (DataRow dr in dtTieng.Rows)
                {
                    lblTrangThai.Text = "Đang cập nhật Tieng: " + dr["Khoa"].ToString();

                    Application.DoEvents();
                    //if (!CheckExitsCB(dr["Khoa"].ToString()))
                    //    continue;

                    #region sqlTieng


                    #region AddParameters
                    arrParametersTieng.Clear();
                    arrParametersTieng.Add(SqlHelper.CreateParameterObject("@Khoa", SqlDbType.NVarChar, ParameterDirection.Input, MyCommon.CurrentUserDauMoiID + "_" + dr["Khoa"]));
                    arrParametersTieng.Add(SqlHelper.CreateParameterObject("@DauMoiID", SqlDbType.Int, ParameterDirection.Input, MyCommon.CurrentUserDauMoiID));
                    arrParametersTieng.Add(SqlHelper.CreateParameterObject("@ID", SqlDbType.Int, ParameterDirection.Input, dr["ID"]));
                    arrParametersTieng.Add(SqlHelper.CreateParameterObject("@Loai", SqlDbType.Int, ParameterDirection.Input, dr["Loai"]));
                    arrParametersTieng.Add(SqlHelper.CreateParameterObject("@NgonNgu_T", SqlDbType.NVarChar, ParameterDirection.Input, Converter.TCVN3ToUnicode(dr["NgonNgu_T"].ToString())));
                    if (dr["Loai"].ToString() == "1")
                    {
                        arrParametersTieng.Add(SqlHelper.CreateParameterObject("@Ma_NNgu", SqlDbType.Int, ParameterDirection.Input, dr["Ma_NNgu"]));
                        arrParametersTieng.Add(SqlHelper.CreateParameterObject("@Ma_DToc", SqlDbType.Int, ParameterDirection.Input, null));
                    }
                    else
                    {
                        arrParametersTieng.Add(SqlHelper.CreateParameterObject("@Ma_NNgu", SqlDbType.Int, ParameterDirection.Input, null));
                        arrParametersTieng.Add(SqlHelper.CreateParameterObject("@Ma_DToc", SqlDbType.Int, ParameterDirection.Input, dr["Ma_DToc"]));
                    }
                    arrParametersTieng.Add(SqlHelper.CreateParameterObject("@TrinhDo", SqlDbType.NVarChar, ParameterDirection.Input, Converter.TCVN3ToUnicode(dr["TrinhDo"].ToString())));
                    arrParametersTieng.Add(SqlHelper.CreateParameterObject("@ThoiGian", SqlDbType.DateTime, ParameterDirection.Input, Util.DATETIME.ToDateFromMMyyyy(dr["ThoiGian"].ToString())));
                    arrParametersTieng.Add(SqlHelper.CreateParameterObject("@UserID", SqlDbType.Int, ParameterDirection.Input, MyCommon.CurrentUserID));

                    #endregion AddParameters


                    SqlHelper.ExecuteNonQuery(CommandType.Text, sqlTieng, arrParametersTieng);

                    #endregion sqlTieng

                }

                #endregion Tieng

                #region ThanNhan

                DataTable dtThanNhan = SqlHelper_Convert.ExecuteDataTable(CommandType.Text, "Select * From ThanNhan ");
                List<SqlParameter> arrParametersThanNhan = new List<SqlParameter>();

                string sqlThanNhan = "";

                #region SQLInsert
                sqlThanNhan = "Insert Into tblThanNhan(ID, Khoa, DauMoiID, Ten_TNhan, Nam_Sinh, Quan_He, DDiem_CT_T, DDiem_KT_T, Nghe, Dia_Chi, Ghi_Chu, UserID, CreateDate) " +
                                "Values(@ID, @Khoa, @DauMoiID, @Ten_TNhan, @Nam_Sinh, @Quan_He, @DDiem_CT_T, @DDiem_KT_T, @Nghe, @Dia_Chi, @Ghi_Chu, @UserID, GetDate()) ";

                #endregion SQLInsert

                foreach (DataRow dr in dtThanNhan.Rows)
                {
                    try
                    {
                        lblTrangThai.Text = "Đang cập nhật ThanhNhan: " + dr["Khoa"].ToString();

                        Application.DoEvents();
                        //if (!CheckExitsCB(dr["Khoa"].ToString()))
                        //    continue;

                        #region sqlThanNhan


                        #region AddParameters
                        arrParametersThanNhan.Clear();
                        arrParametersThanNhan.Add(SqlHelper.CreateParameterObject("@Khoa", SqlDbType.NVarChar, ParameterDirection.Input, MyCommon.CurrentUserDauMoiID + "_" + dr["Khoa"]));
                        arrParametersThanNhan.Add(SqlHelper.CreateParameterObject("@DauMoiID", SqlDbType.Int, ParameterDirection.Input, MyCommon.CurrentUserDauMoiID));

                        arrParametersThanNhan.Add(SqlHelper.CreateParameterObject("@ID", SqlDbType.Int, ParameterDirection.Input, dr["ID"]));

                        arrParametersThanNhan.Add(SqlHelper.CreateParameterObject("@Ten_TNhan", SqlDbType.NVarChar, ParameterDirection.Input, Converter.TCVN3ToUnicode(dr["Ten_TNhan"].ToString())));
                        arrParametersThanNhan.Add(SqlHelper.CreateParameterObject("@Nam_Sinh", SqlDbType.NVarChar, ParameterDirection.Input, dr["Nam_Sinh"]));
                        arrParametersThanNhan.Add(SqlHelper.CreateParameterObject("@Quan_He", SqlDbType.Int, ParameterDirection.Input, dr["Quan_He"]));
                        arrParametersThanNhan.Add(SqlHelper.CreateParameterObject("@DDiem_CT_T", SqlDbType.NVarChar, ParameterDirection.Input, Converter.TCVN3ToUnicode(dr["DDiem_CT_T"].ToString())));
                        arrParametersThanNhan.Add(SqlHelper.CreateParameterObject("@DDiem_KT_T", SqlDbType.NVarChar, ParameterDirection.Input, Converter.TCVN3ToUnicode(dr["DDiem_KT_T"].ToString())));
                        arrParametersThanNhan.Add(SqlHelper.CreateParameterObject("@Nghe", SqlDbType.NVarChar, ParameterDirection.Input, Converter.TCVN3ToUnicode(dr["Nghe"].ToString())));
                        arrParametersThanNhan.Add(SqlHelper.CreateParameterObject("@Dia_Chi", SqlDbType.NVarChar, ParameterDirection.Input, Converter.TCVN3ToUnicode(dr["Dia_Chi"].ToString())));
                        arrParametersThanNhan.Add(SqlHelper.CreateParameterObject("@Ghi_Chu", SqlDbType.NVarChar, ParameterDirection.Input, Converter.TCVN3ToUnicode(dr["Ghi_Chu"].ToString())));
                        arrParametersThanNhan.Add(SqlHelper.CreateParameterObject("@UserID", SqlDbType.Int, ParameterDirection.Input, MyCommon.CurrentUserID));

                        #endregion AddParameters


                        SqlHelper.ExecuteNonQuery(CommandType.Text, sqlThanNhan, arrParametersThanNhan);

                        #endregion sqlThanNhan
                    }
                    catch { }

                }

                #endregion ThanNhan
                //TODO: cho hàm chuyển đổi font từ bảng cán bộ trở xuống
                lblTrangThai.Text = "Thực hiện xong";
                MyCommon.ShowMessage("thực hiện xong");
            }
            catch (Exception _ex)
            {
                MyCommon.ShowDialogMessage(_ex);
            }
        }

        private void simpleButton1_Click(object sender, EventArgs e)
        {
            txtDatabase.Text = Util.DATETIME.ToDate(SqlHelper.ExecuteScalar(CommandType.Text, "Select ngay_sinh from tblcanbo")).Value.ToString(MyConst.FORMAT_DATETIME.ddMMyyyy);
        }

        private void simpleButton2_Click(object sender, EventArgs e)
        {
            try
            {
                SqlHelper_Convert.ConnectDatabase(txtServer.Text.Trim(), txtUser.Text.Trim(), txtPass.Text.Trim(), txtDatabase.Text.Trim());

                string sqlTemp1 = "Delete From tblTrichNgang Where Khoa In (Select Khoa From tblCanBo Where ChuyenRa=1 And DauMoiID='" + MyCommon.CurrentUserDauMoiID + "') ; ";
                sqlTemp1 += "Delete From tblKhac Where Khoa In (Select Khoa From tblCanBo Where ChuyenRa=1 And DauMoiID='" + MyCommon.CurrentUserDauMoiID + "') ; ";
                sqlTemp1 += "Delete From tblQT_CD Where Khoa In (Select Khoa From tblCanBo Where ChuyenRa=1 And DauMoiID='" + MyCommon.CurrentUserDauMoiID + "') ; ";
                sqlTemp1 += "Delete From tblQT_CT Where Khoa In (Select Khoa From tblCanBo Where ChuyenRa=1 And DauMoiID='" + MyCommon.CurrentUserDauMoiID + "') ; ";
                sqlTemp1 += "Delete From tblQT_DG Where Khoa In (Select Khoa From tblCanBo Where ChuyenRa=1 And DauMoiID='" + MyCommon.CurrentUserDauMoiID + "') ; ";
                sqlTemp1 += "Delete From tblQT_DT Where Khoa In (Select Khoa From tblCanBo Where ChuyenRa=1 And DauMoiID='" + MyCommon.CurrentUserDauMoiID + "') ; ";
                sqlTemp1 += "Delete From tblTieng Where Khoa In (Select Khoa From tblCanBo Where ChuyenRa=1 And DauMoiID='" + MyCommon.CurrentUserDauMoiID + "') ; ";
                sqlTemp1 += "Delete From tblThanNhan Where Khoa In (Select Khoa From tblCanBo Where ChuyenRa=1 And DauMoiID='" + MyCommon.CurrentUserDauMoiID + "') ; ";
                sqlTemp1 += "Delete From tblCanBo Where ChuyenRa=1 And DauMoiID='" + MyCommon.CurrentUserDauMoiID + "' ; ";

                SqlHelper.ExecuteNonQuery(CommandType.Text, sqlTemp1);

                #region CanBo

                DataTable dtCanBo = SqlHelper_Convert.ExecuteDataTable(CommandType.Text, "Select * From CANBO ");
                string sqlCanBo = "";
                int maxKhoa = 0;
                List<SqlParameter> arrParametersCanBo = new List<SqlParameter>();

                #region SQLInsert
                sqlCanBo = "INSERT INTO  tblCanBo(DauMoiID, Khoa, So_Hieu_SQ, So_Hieu_QN, HoTen_KS " +
                                               ", BiDanh, Ho, Dem, Ten, Ten_Khac, Cap_Bac, Thang_CBac " +
                                               ", Lan_NLuong, HeSoLuong, Bac_Luong, Muc_Luong, LuongChinh, Thang_NL " +
                                               ", Chuc_Vu, Thang_CVu, Chuc_Kiem, Dung_CVCT, Loai_DV, Don_Vi_CT " +
                                               ", Khoi_CTac, Ngay_Sinh, Gioi_Tinh, Binh_Chung, Nganh_CTac, Dan_Toc_T " +
                                               ", Ton_Giao_T, Loai_CBo, Van_Hoa, CHQL, LLCT, CMNV, HocHam, HocVi, DanhHieu " +
                                               ", Nguon_VDN, Gia_Dinh_T, Ban_Than_T, Ngay_VDang, Ngay_CDCT, CVu_Dang_T " +
                                               ", CVu_DThe_T, Thang_Doan, Thang_CM, Thang_BC, Thang_NNgu, Thang_XNgu " +
                                               ", Thang_TNgu, NQuan_HT, NQuan_XP, TQuan_HT, TQuan_XP, Loai_No_T " +
                                               ", DTich_No, Nguon_Go_T, Dia_Chi, Loai_SKhoe, Benh_Chi_T, Thuong_T_T " +
                                               ", Huong_SD, Ly_Do_Vao, Ly_Do_Ra, Ngay_Vao, Ngay_Ra, Cap_Nhat_C " +
                                               ", Status, Ngach_Luong, Picture, Deleted, ChuyenRa " +
                                               ", UserID, DauMoi_ID, CreateDate) " +
                                    "VALUES (@DauMoiID, @Khoa, @So_Hieu_SQ, @So_Hieu_QN, @HoTen_KS " +
                                               ", @BiDanh, @Ho, @Dem, @Ten, @Ten_Khac, @Cap_Bac, @Thang_CBac " +
                                               ", @Lan_NLuong, @HeSoLuong, @Bac_Luong, @Muc_Luong, @LuongChinh, @Thang_NL " +
                                               ", @Chuc_Vu, @Thang_CVu, @Chuc_Kiem, @Dung_CVCT, @Loai_DV, @Don_Vi_CT " +
                                               ", @Khoi_CTac, @Ngay_Sinh, @Gioi_Tinh, @Binh_Chung, @Nganh_CTac, @Dan_Toc_T " +
                                               ", @Ton_Giao_T, @Loai_CBo, @Van_Hoa, @CHQL, @LLCT, @CMNV, @HocHam, @HocVi, @DanhHieu " +
                                               ", @Nguon_VDN, @Gia_Dinh_T, @Ban_Than_T, @Ngay_VDang, @Ngay_CDCT, @CVu_Dang_T " +
                                               ", @CVu_DThe_T, @Thang_Doan, @Thang_CM, @Thang_BC, @Thang_NNgu, @Thang_XNgu " +
                                               ", @Thang_TNgu, @NQuan_HT, @NQuan_XP, @TQuan_HT, @TQuan_XP, @Loai_No_T " +
                                               ", @DTich_No, @Nguon_Go_T, @Dia_Chi, @Loai_SKhoe, @Benh_Chi_T, @Thuong_T_T " +
                                               ", @Huong_SD, @Ly_Do_Vao, @Ly_Do_Ra, @Ngay_Vao, @Ngay_Ra, @Cap_Nhat_C " +
                                               ", @Status, @Ngach_Luong, @Picture, @Deleted, @ChuyenRa " +
                                               ", @UserID, @DauMoi_ID, GetDate()); ";


                #endregion SQLInsert

                DataTable temDTCB = new DataTable();
                foreach (DataRow dr in dtCanBo.Rows)
                {
                    //try
                    //{
                    #region sqlCanBo

                    lblTrangThai.Text = "Đang chuyển đổi hồ sơ cán bộ: " + dr["khoa"].ToString();

                    Application.DoEvents();
                    #region Parameters





                    arrParametersCanBo.Clear();
                    arrParametersCanBo.Add(SqlHelper.CreateParameterObject("@DauMoiID", SqlDbType.Int, ParameterDirection.Input, MyCommon.CurrentUserDauMoiID));

                    arrParametersCanBo.Add(SqlHelper.CreateParameterObject("@Khoa", SqlDbType.NVarChar, ParameterDirection.Input, MyCommon.CurrentUserDauMoiID + "_" + dr["Khoa"]));

                    #region kiểm tra xem tồn tại chưa:

                    temDTCB = SqlHelper.ExecuteDataTable(CommandType.Text, "Select Khoa From tblCanBo Where Khoa=@Khoa ", arrParametersCanBo);
                    if (temDTCB.Rows.Count > 0)
                    {
                        arrParametersCanBo.Add(SqlHelper.CreateParameterObject("@KhoaDel", SqlDbType.NVarChar, ParameterDirection.Input, dr["Khoa"]));

                        SqlHelper_Convert.ExecuteNonQuery(CommandType.Text, "Delete from Khac where khoa=@KhoaDel; Delete from qt_cd where khoa=@KhoaDel; Delete from qt_ct where khoa=@KhoaDel; Delete from qt_dg where khoa=@KhoaDel; Delete from qt_dt where khoa=@KhoaDel; Delete from tb_trichngang where khoa=@KhoaDel; Delete from thannhan where khoa=@KhoaDel; Delete from tieng where khoa=@KhoaDel; ", arrParametersCanBo);

                        continue;
                    }

                    #endregion kiểm tra xem tồn tại chưa:



                    arrParametersCanBo.Add(SqlHelper.CreateParameterObject("@So_Hieu_SQ", SqlDbType.NVarChar, ParameterDirection.Input, dr["So_Hieu_SQ"]));
                    arrParametersCanBo.Add(SqlHelper.CreateParameterObject("@So_Hieu_QN", SqlDbType.NVarChar, ParameterDirection.Input, dr["So_Hieu_QN"]));
                    arrParametersCanBo.Add(SqlHelper.CreateParameterObject("@HoTen_KS", SqlDbType.NVarChar, ParameterDirection.Input, Converter.TCVN3ToUnicode(dr["HoTen_KS"].ToString())));
                    arrParametersCanBo.Add(SqlHelper.CreateParameterObject("@BiDanh", SqlDbType.NVarChar, ParameterDirection.Input, Converter.TCVN3ToUnicode(dr["BiDanh"].ToString())));
                    arrParametersCanBo.Add(SqlHelper.CreateParameterObject("@Ho", SqlDbType.NVarChar, ParameterDirection.Input, Converter.TCVN3ToUnicode(dr["Ho"].ToString())));
                    arrParametersCanBo.Add(SqlHelper.CreateParameterObject("@Dem", SqlDbType.NVarChar, ParameterDirection.Input, Converter.TCVN3ToUnicode(dr["Dem"].ToString())));
                    arrParametersCanBo.Add(SqlHelper.CreateParameterObject("@Ten", SqlDbType.NVarChar, ParameterDirection.Input, Converter.TCVN3ToUnicode(dr["Ten"].ToString())));
                    arrParametersCanBo.Add(SqlHelper.CreateParameterObject("@Ten_Khac", SqlDbType.NVarChar, ParameterDirection.Input, Converter.TCVN3ToUnicode(dr["Ten_Khac"].ToString())));
                    arrParametersCanBo.Add(SqlHelper.CreateParameterObject("@Cap_Bac", SqlDbType.Int, ParameterDirection.Input, dr["Cap_Bac"]));
                    arrParametersCanBo.Add(SqlHelper.CreateParameterObject("@Thang_CBac", SqlDbType.DateTime, ParameterDirection.Input, Util.DATETIME.ToDateFromMMyyyy(dr["Thang_CBac"].ToString())));
                    arrParametersCanBo.Add(SqlHelper.CreateParameterObject("@Lan_NLuong", SqlDbType.Int, ParameterDirection.Input, dr["Lan_NLuong"]));
                    arrParametersCanBo.Add(SqlHelper.CreateParameterObject("@HeSoLuong", SqlDbType.Float, ParameterDirection.Input, dr["HeSoLuong"]));
                    arrParametersCanBo.Add(SqlHelper.CreateParameterObject("@Bac_Luong", SqlDbType.Float, ParameterDirection.Input, dr["Bac_Luong"]));
                    arrParametersCanBo.Add(SqlHelper.CreateParameterObject("@Muc_Luong", SqlDbType.Float, ParameterDirection.Input, dr["Muc_Luong"]));
                    arrParametersCanBo.Add(SqlHelper.CreateParameterObject("@LuongChinh", SqlDbType.Float, ParameterDirection.Input, 0));
                    arrParametersCanBo.Add(SqlHelper.CreateParameterObject("@Thang_NL", SqlDbType.DateTime, ParameterDirection.Input, Util.DATETIME.ToDateFromMMyyyy(dr["Thang_NL"].ToString())));
                    arrParametersCanBo.Add(SqlHelper.CreateParameterObject("@Chuc_Vu", SqlDbType.Int, ParameterDirection.Input, dr["Chuc_Vu"]));
                    arrParametersCanBo.Add(SqlHelper.CreateParameterObject("@Thang_CVu", SqlDbType.DateTime, ParameterDirection.Input, Util.DATETIME.ToDateFromMMyyyy(dr["Thang_CVu"].ToString())));
                    arrParametersCanBo.Add(SqlHelper.CreateParameterObject("@Chuc_Kiem", SqlDbType.NVarChar, ParameterDirection.Input, Converter.TCVN3ToUnicode(dr["Chuc_Kiem"].ToString())));
                    arrParametersCanBo.Add(SqlHelper.CreateParameterObject("@Dung_CVCT", SqlDbType.NVarChar, ParameterDirection.Input, ""));
                    arrParametersCanBo.Add(SqlHelper.CreateParameterObject("@Loai_DV", SqlDbType.Int, ParameterDirection.Input, null));
                    arrParametersCanBo.Add(SqlHelper.CreateParameterObject("@Don_Vi_CT", SqlDbType.Int, ParameterDirection.Input, dr["Don_Vi_CT"]));
                    arrParametersCanBo.Add(SqlHelper.CreateParameterObject("@Khoi_CTac", SqlDbType.Int, ParameterDirection.Input, dr["Khoi_CTac"]));
                    arrParametersCanBo.Add(SqlHelper.CreateParameterObject("@Ngay_Sinh", SqlDbType.DateTime, ParameterDirection.Input, Util.DATETIME.ParseNgaySinh(dr["Ngay_Sinh"].ToString())));
                    arrParametersCanBo.Add(SqlHelper.CreateParameterObject("@Gioi_Tinh", SqlDbType.NVarChar, ParameterDirection.Input, Converter.TCVN3ToUnicode(dr["Gioi_Tinh"].ToString())));
                    arrParametersCanBo.Add(SqlHelper.CreateParameterObject("@Binh_Chung", SqlDbType.Int, ParameterDirection.Input, dr["Binh_Chung"]));
                    arrParametersCanBo.Add(SqlHelper.CreateParameterObject("@Nganh_CTac", SqlDbType.Int, ParameterDirection.Input, dr["Nganh_CTac"]));
                    arrParametersCanBo.Add(SqlHelper.CreateParameterObject("@Dan_Toc_T", SqlDbType.NVarChar, ParameterDirection.Input, Converter.TCVN3ToUnicode(dr["Dan_Toc_T"].ToString())));
                    arrParametersCanBo.Add(SqlHelper.CreateParameterObject("@Ton_Giao_T", SqlDbType.NVarChar, ParameterDirection.Input, Converter.TCVN3ToUnicode(dr["Ton_Giao_T"].ToString())));
                    arrParametersCanBo.Add(SqlHelper.CreateParameterObject("@Loai_CBo", SqlDbType.Int, ParameterDirection.Input, dr["Loai_CBo"]));
                    arrParametersCanBo.Add(SqlHelper.CreateParameterObject("@Van_Hoa", SqlDbType.Int, ParameterDirection.Input, dr["Van_Hoa"]));
                    arrParametersCanBo.Add(SqlHelper.CreateParameterObject("@CHQL", SqlDbType.NVarChar, ParameterDirection.Input, Converter.TCVN3ToUnicode(dr["CHQL"].ToString())));
                    arrParametersCanBo.Add(SqlHelper.CreateParameterObject("@LLCT", SqlDbType.NVarChar, ParameterDirection.Input, Converter.TCVN3ToUnicode(dr["LLCT"].ToString())));
                    arrParametersCanBo.Add(SqlHelper.CreateParameterObject("@CMNV", SqlDbType.NVarChar, ParameterDirection.Input, Converter.TCVN3ToUnicode(dr["CMNV"].ToString())));
                    arrParametersCanBo.Add(SqlHelper.CreateParameterObject("@HocHam", SqlDbType.Int, ParameterDirection.Input, dr["HocHam"]));
                    arrParametersCanBo.Add(SqlHelper.CreateParameterObject("@HocVi", SqlDbType.Int, ParameterDirection.Input, dr["HocVi"]));
                    arrParametersCanBo.Add(SqlHelper.CreateParameterObject("@DanhHieu", SqlDbType.NVarChar, ParameterDirection.Input, Converter.TCVN3ToUnicode(dr["DanhHieu"].ToString())));
                    arrParametersCanBo.Add(SqlHelper.CreateParameterObject("@Nguon_VDN", SqlDbType.Int, ParameterDirection.Input, dr["Nguon_VDN"]));
                    arrParametersCanBo.Add(SqlHelper.CreateParameterObject("@Gia_Dinh_T", SqlDbType.NVarChar, ParameterDirection.Input, Converter.TCVN3ToUnicode(dr["Gia_Dinh_T"].ToString())));
                    arrParametersCanBo.Add(SqlHelper.CreateParameterObject("@Ban_Than_T", SqlDbType.NVarChar, ParameterDirection.Input, Converter.TCVN3ToUnicode(dr["Ban_Than_T"].ToString())));
                    arrParametersCanBo.Add(SqlHelper.CreateParameterObject("@Ngay_VDang", SqlDbType.DateTime, ParameterDirection.Input, Util.DATETIME.ToDateFromMMyyyy(dr["Ngay_VDang"].ToString())));
                    arrParametersCanBo.Add(SqlHelper.CreateParameterObject("@Ngay_CDCT", SqlDbType.DateTime, ParameterDirection.Input, Util.DATETIME.ToDateFromMMyyyy(dr["Ngay_CDCT"].ToString())));
                    arrParametersCanBo.Add(SqlHelper.CreateParameterObject("@CVu_Dang_T", SqlDbType.NVarChar, ParameterDirection.Input, Converter.TCVN3ToUnicode(dr["CVu_Dang_T"].ToString())));
                    arrParametersCanBo.Add(SqlHelper.CreateParameterObject("@CVu_DThe_T", SqlDbType.NVarChar, ParameterDirection.Input, Converter.TCVN3ToUnicode(dr["CVu_DThe_T"].ToString())));
                    arrParametersCanBo.Add(SqlHelper.CreateParameterObject("@Thang_Doan", SqlDbType.DateTime, ParameterDirection.Input, Util.DATETIME.ToDateFromMMyyyy(dr["Thang_Doan"].ToString())));
                    arrParametersCanBo.Add(SqlHelper.CreateParameterObject("@Thang_CM", SqlDbType.DateTime, ParameterDirection.Input, Util.DATETIME.ToDateFromMMyyyy(dr["Thang_CM"].ToString())));
                    arrParametersCanBo.Add(SqlHelper.CreateParameterObject("@Thang_BC", SqlDbType.DateTime, ParameterDirection.Input, Util.DATETIME.ToDateFromMMyyyy(dr["Thang_BC"].ToString())));
                    arrParametersCanBo.Add(SqlHelper.CreateParameterObject("@Thang_NNgu", SqlDbType.DateTime, ParameterDirection.Input, Util.DATETIME.ToDateFromMMyyyy(dr["Thang_NNgu"].ToString())));
                    arrParametersCanBo.Add(SqlHelper.CreateParameterObject("@Thang_XNgu", SqlDbType.DateTime, ParameterDirection.Input, Util.DATETIME.ToDateFromMMyyyy(dr["Thang_XNgu"].ToString())));
                    arrParametersCanBo.Add(SqlHelper.CreateParameterObject("@Thang_TNgu", SqlDbType.DateTime, ParameterDirection.Input, Util.DATETIME.ToDateFromMMyyyy(dr["Thang_TNgu"].ToString())));
                    arrParametersCanBo.Add(SqlHelper.CreateParameterObject("@NQuan_HT", SqlDbType.Int, ParameterDirection.Input, dr["NQuan_HT"]));
                    arrParametersCanBo.Add(SqlHelper.CreateParameterObject("@NQuan_XP", SqlDbType.NVarChar, ParameterDirection.Input, Converter.TCVN3ToUnicode(dr["NQuan_XP"].ToString())));
                    arrParametersCanBo.Add(SqlHelper.CreateParameterObject("@TQuan_HT", SqlDbType.Int, ParameterDirection.Input, dr["TQuan_HT"]));
                    arrParametersCanBo.Add(SqlHelper.CreateParameterObject("@TQuan_XP", SqlDbType.NVarChar, ParameterDirection.Input, Converter.TCVN3ToUnicode(dr["TQuan_XP"].ToString())));
                    arrParametersCanBo.Add(SqlHelper.CreateParameterObject("@Loai_No_T", SqlDbType.NVarChar, ParameterDirection.Input, Converter.TCVN3ToUnicode(dr["Loai_No_T"].ToString())));
                    arrParametersCanBo.Add(SqlHelper.CreateParameterObject("@DTich_No", SqlDbType.Float, ParameterDirection.Input, dr["DTich_No"]));
                    arrParametersCanBo.Add(SqlHelper.CreateParameterObject("@Nguon_Go_T", SqlDbType.NVarChar, ParameterDirection.Input, Converter.TCVN3ToUnicode(dr["Nguon_Go_T"].ToString())));
                    arrParametersCanBo.Add(SqlHelper.CreateParameterObject("@Dia_Chi", SqlDbType.NVarChar, ParameterDirection.Input, Converter.TCVN3ToUnicode(dr["Dia_Chi"].ToString())));
                    arrParametersCanBo.Add(SqlHelper.CreateParameterObject("@Loai_SKhoe", SqlDbType.Int, ParameterDirection.Input, dr["Loai_SKhoe"]));
                    arrParametersCanBo.Add(SqlHelper.CreateParameterObject("@Benh_Chi_T", SqlDbType.NVarChar, ParameterDirection.Input, Converter.TCVN3ToUnicode(dr["Benh_Chi_T"].ToString())));
                    arrParametersCanBo.Add(SqlHelper.CreateParameterObject("@Thuong_T_T", SqlDbType.NVarChar, ParameterDirection.Input, Converter.TCVN3ToUnicode(dr["Thuong_T_T"].ToString())));
                    arrParametersCanBo.Add(SqlHelper.CreateParameterObject("@Huong_SD", SqlDbType.Int, ParameterDirection.Input, dr["Huong_SD"]));
                    arrParametersCanBo.Add(SqlHelper.CreateParameterObject("@Ly_Do_Vao", SqlDbType.Int, ParameterDirection.Input, dr["Ly_Do_Vao"]));
                    arrParametersCanBo.Add(SqlHelper.CreateParameterObject("@Ly_Do_Ra", SqlDbType.Int, ParameterDirection.Input, dr["Ly_Do_Ra"]));
                    arrParametersCanBo.Add(SqlHelper.CreateParameterObject("@Ngay_Vao", SqlDbType.DateTime, ParameterDirection.Input, dr["Ngay_Vao"]));
                    arrParametersCanBo.Add(SqlHelper.CreateParameterObject("@Ngay_Ra", SqlDbType.DateTime, ParameterDirection.Input, dr["Ngay_Ra"]));
                    arrParametersCanBo.Add(SqlHelper.CreateParameterObject("@Cap_Nhat_C", SqlDbType.NVarChar, ParameterDirection.Input, ""));

                    arrParametersCanBo.Add(SqlHelper.CreateParameterObject("@Status", SqlDbType.NVarChar, ParameterDirection.Input, ""));
                    arrParametersCanBo.Add(SqlHelper.CreateParameterObject("@Ngach_Luong", SqlDbType.NVarChar, ParameterDirection.Input, Converter.TCVN3ToUnicode(dr["Ngach_Luong"].ToString())));


                    arrParametersCanBo.Add(SqlHelper.CreateParameterObject("@Picture", SqlDbType.Image, ParameterDirection.Input, dr["Picture"]));

                    arrParametersCanBo.Add(SqlHelper.CreateParameterObject("@Deleted", SqlDbType.Bit, ParameterDirection.Input, false));
                    arrParametersCanBo.Add(SqlHelper.CreateParameterObject("@ChuyenRa", SqlDbType.Bit, ParameterDirection.Input, true));
                    arrParametersCanBo.Add(SqlHelper.CreateParameterObject("@UserID", SqlDbType.Int, ParameterDirection.Input, MyCommon.CurrentUserID));
                    arrParametersCanBo.Add(SqlHelper.CreateParameterObject("@DauMoi_ID", SqlDbType.Int, ParameterDirection.Input, MyCommon.CurrentUserDauMoiID));

                    #endregion Parameters


                    SqlHelper.ExecuteNonQuery(CommandType.Text, sqlCanBo, arrParametersCanBo);

                    #endregion sqlCanBo

                    //}
                    //catch (Exception _ex)
                    //{
                    //    throw _ex;
                    //}
                }
                arrParametersCanBo.Clear();
                arrParametersCanBo.Add(SqlHelper.CreateParameterObject("@DauMoiID", SqlDbType.Int, ParameterDirection.Input, MyCommon.CurrentUserDauMoiID));

                maxKhoa = Util.ToInt(SqlHelper.ExecuteScalar(CommandType.Text, "Select Max(Khoa) From tblCanBo Where DauMoiID=@DauMoiID ", arrParametersCanBo));

                sqlCanBo = "Update tblDau_Moi Set CurentID=" + maxKhoa + " Where ID=@DauMoiID ";
                SqlHelper.ExecuteNonQuery(CommandType.Text, sqlCanBo, arrParametersCanBo);

                #endregion CanBo

                #region TrichNgang

                DataTable dtTrichNgang = SqlHelper_Convert.ExecuteDataTable(CommandType.Text, "Select * From tb_TrichNgang ");
                List<SqlParameter> arrParametersTrichNgang = new List<SqlParameter>();


                #region SQLInsert
                string sqlTrichNgang = "Insert Into tblTrichNgang(Khoa, DauMoiID, Ngay_HH, Ngay_HV, Di_NN, Truoc_CM, KTCT_BT, KTCT_VC, Nhan_Xet, So_ACE, So_AET, So_ACE_VC, So_AET_VC, Thu_May, Thu_May_VC, Ma_Gia_Dinh_VC, Ma_Ban_Than_VC, Que_Quan_XPVC, Tru_Quan_XPVC, Que_Quan_HTVC, Tru_Quan_HTVC, Ghi_Them, Ngay_Trich, Can_Cu_Trich, UserID, CreateDate) " +
                           "Values(@Khoa, @DauMoiID, @Ngay_HH, @Ngay_HV, @Di_NN, @Truoc_CM, @KTCT_BT, @KTCT_VC, @Nhan_Xet, @So_ACE, @So_AET, @So_ACE_VC, @So_AET_VC, @Thu_May, @Thu_May_VC, @Ma_Gia_Dinh_VC, @Ma_Ban_Than_VC, @Que_Quan_XPVC, @Tru_Quan_XPVC, @Que_Quan_HTVC, @Tru_Quan_HTVC, @Ghi_Them, @Ngay_Trich, @Can_Cu_Trich, @UserID, GetDate()) ";

                #endregion SQLInsert

                foreach (DataRow dr in dtTrichNgang.Rows)
                {
                    #region sqlTrichNgang

                    lblTrangThai.Text = "Đang chuyển đổi hồ sơ trích ngang: " + dr["Khoa"].ToString();

                    Application.DoEvents();




                    #region AddParameters
                    arrParametersTrichNgang.Clear();

                    arrParametersTrichNgang.Add(SqlHelper.CreateParameterObject("@Khoa", SqlDbType.NVarChar, ParameterDirection.Input, MyCommon.CurrentUserDauMoiID + "_" + dr["Khoa"]));
                    arrParametersTrichNgang.Add(SqlHelper.CreateParameterObject("@DauMoiID", SqlDbType.Int, ParameterDirection.Input, MyCommon.CurrentUserDauMoiID));
                    arrParametersTrichNgang.Add(SqlHelper.CreateParameterObject("@Ngay_HH", SqlDbType.DateTime, ParameterDirection.Input, null));
                    arrParametersTrichNgang.Add(SqlHelper.CreateParameterObject("@Ngay_HV", SqlDbType.DateTime, ParameterDirection.Input, null));
                    arrParametersTrichNgang.Add(SqlHelper.CreateParameterObject("@Di_NN", SqlDbType.NVarChar, ParameterDirection.Input, Converter.TCVN3ToUnicode(dr["Di_NN"].ToString())));
                    arrParametersTrichNgang.Add(SqlHelper.CreateParameterObject("@Truoc_CM", SqlDbType.NVarChar, ParameterDirection.Input, Converter.TCVN3ToUnicode(dr["Truoc_CM"].ToString())));
                    arrParametersTrichNgang.Add(SqlHelper.CreateParameterObject("@KTCT_BT", SqlDbType.NVarChar, ParameterDirection.Input, Converter.TCVN3ToUnicode(dr["KTCT_BT"].ToString())));

                    arrParametersTrichNgang.Add(SqlHelper.CreateParameterObject("@KTCT_VC", SqlDbType.NVarChar, ParameterDirection.Input, Converter.TCVN3ToUnicode(dr["KTCT_VC"].ToString())));
                    arrParametersTrichNgang.Add(SqlHelper.CreateParameterObject("@Nhan_Xet", SqlDbType.NVarChar, ParameterDirection.Input, Converter.TCVN3ToUnicode(dr["Nhan_Xet"].ToString())));
                    arrParametersTrichNgang.Add(SqlHelper.CreateParameterObject("@So_ACE", SqlDbType.Int, ParameterDirection.Input, dr["So_ACE"]));
                    arrParametersTrichNgang.Add(SqlHelper.CreateParameterObject("@So_AET", SqlDbType.Int, ParameterDirection.Input, dr["So_AET"]));
                    arrParametersTrichNgang.Add(SqlHelper.CreateParameterObject("@So_ACE_VC", SqlDbType.Int, ParameterDirection.Input, dr["So_ACE_VC"]));
                    arrParametersTrichNgang.Add(SqlHelper.CreateParameterObject("@So_AET_VC", SqlDbType.Int, ParameterDirection.Input, dr["So_AET_VC"]));
                    arrParametersTrichNgang.Add(SqlHelper.CreateParameterObject("@Thu_May", SqlDbType.Int, ParameterDirection.Input, dr["Thu_May"]));
                    arrParametersTrichNgang.Add(SqlHelper.CreateParameterObject("@Thu_May_VC", SqlDbType.Int, ParameterDirection.Input, dr["Thu_May_VC"]));
                    arrParametersTrichNgang.Add(SqlHelper.CreateParameterObject("@Ma_Gia_Dinh_VC", SqlDbType.Int, ParameterDirection.Input, dr["Ma_Gia_Dinh_VC"]));
                    arrParametersTrichNgang.Add(SqlHelper.CreateParameterObject("@Ma_Ban_Than_VC", SqlDbType.Int, ParameterDirection.Input, dr["Ma_Ban_Than_VC"]));
                    arrParametersTrichNgang.Add(SqlHelper.CreateParameterObject("@Que_Quan_XPVC", SqlDbType.NVarChar, ParameterDirection.Input, Converter.TCVN3ToUnicode(dr["Que_Quan_XPVC"].ToString())));
                    arrParametersTrichNgang.Add(SqlHelper.CreateParameterObject("@Tru_Quan_XPVC", SqlDbType.NVarChar, ParameterDirection.Input, Converter.TCVN3ToUnicode(dr["Tru_Quan_XPVC"].ToString())));
                    arrParametersTrichNgang.Add(SqlHelper.CreateParameterObject("@Que_Quan_HTVC", SqlDbType.NVarChar, ParameterDirection.Input, Converter.TCVN3ToUnicode(dr["Que_Quan_HTVC"].ToString())));
                    arrParametersTrichNgang.Add(SqlHelper.CreateParameterObject("@Tru_Quan_HTVC", SqlDbType.NVarChar, ParameterDirection.Input, Converter.TCVN3ToUnicode(dr["Tru_Quan_HTVC"].ToString())));
                    arrParametersTrichNgang.Add(SqlHelper.CreateParameterObject("@Ghi_Them", SqlDbType.NVarChar, ParameterDirection.Input, ""));

                    arrParametersTrichNgang.Add(SqlHelper.CreateParameterObject("@Ngay_Trich", SqlDbType.DateTime, ParameterDirection.Input, null));
                    arrParametersTrichNgang.Add(SqlHelper.CreateParameterObject("@Can_Cu_Trich", SqlDbType.NVarChar, ParameterDirection.Input, ""));
                    arrParametersTrichNgang.Add(SqlHelper.CreateParameterObject("@UserID", SqlDbType.NVarChar, ParameterDirection.Input, MyCommon.CurrentUserID));

                    #endregion AddParameters


                    SqlHelper.ExecuteNonQuery(CommandType.Text, sqlTrichNgang, arrParametersTrichNgang);

                    #endregion sqlTrichNgang

                }

                #endregion TrichNgang

                #region Khac

                DataTable dtKhac = SqlHelper_Convert.ExecuteDataTable(CommandType.Text, "Select * From Khac ");
                List<SqlParameter> arrParametersKhac = new List<SqlParameter>();

                string sqlKhac = "";

                #region SQLInsert
                sqlKhac = "Insert Into tblKhac(ID, Khoa, DauMoiID, Thang_SK, Noi_Dung, UserID, CreateDate) " +
                                "Values(@ID, @Khoa, @DauMoiID, @Thang_SK, @Noi_Dung, @UserID, GetDate()) ";

                #endregion SQLInsert

                foreach (DataRow dr in dtKhac.Rows)
                {
                    #region sqlKhac

                    lblTrangThai.Text = "Đang chuyển đổi hồ sơ khác của cán bộ: " + dr["ID"].ToString();

                    Application.DoEvents();





                    #region AddParameters
                    arrParametersKhac.Clear();

                    arrParametersKhac.Add(SqlHelper.CreateParameterObject("@Khoa", SqlDbType.NVarChar, ParameterDirection.Input, MyCommon.CurrentUserDauMoiID + "_" + dr["Khoa"]));
                    arrParametersKhac.Add(SqlHelper.CreateParameterObject("@DauMoiID", SqlDbType.Int, ParameterDirection.Input, MyCommon.CurrentUserDauMoiID));
                    arrParametersKhac.Add(SqlHelper.CreateParameterObject("@ID", SqlDbType.Int, ParameterDirection.Input, dr["ID"]));

                    arrParametersKhac.Add(SqlHelper.CreateParameterObject("@Thang_SK", SqlDbType.DateTime, ParameterDirection.Input, Util.DATETIME.ToDateFromMMyyyy(dr["Thang_SK"].ToString())));
                    arrParametersKhac.Add(SqlHelper.CreateParameterObject("@Noi_Dung", SqlDbType.NVarChar, ParameterDirection.Input, Converter.TCVN3ToUnicode(dr["Noi_Dung"].ToString())));
                    arrParametersKhac.Add(SqlHelper.CreateParameterObject("@UserID", SqlDbType.Int, ParameterDirection.Input, MyCommon.CurrentUserID));

                    #endregion AddParameters


                    SqlHelper.ExecuteNonQuery(CommandType.Text, sqlKhac, arrParametersKhac);

                    #endregion sqlKhac

                }

                #endregion Khac

                #region QT_CD

                DataTable dtQT_CD = SqlHelper_Convert.ExecuteDataTable(CommandType.Text, "Select * From QT_CD ");
                List<SqlParameter> arrParametersQT_CD = new List<SqlParameter>();

                string sqlQT_CD = "";

                #region SQLInsert
                sqlQT_CD = "Insert Into tblQT_CD(ID, Khoa, DauMoiID, Ch_Truong, Bat_Dau, Ket_Thuc, CVi_ChDau, Don_Vi, UserID, CreateDate) " +
                                "Values(@ID, @Khoa, @DauMoiID, @Ch_Truong, @Bat_Dau, @Ket_Thuc, @CVi_ChDau, @Don_Vi, @UserID, GetDate()); ";

                #endregion SQLInsert

                foreach (DataRow dr in dtQT_CD.Rows)
                {
                    lblTrangThai.Text = "Đang cập nhật QT_CD: " + dr["Khoa"].ToString();

                    Application.DoEvents();
                    //if (!CheckExitsCB(dr["Khoa"].ToString()))
                    //    continue;

                    #region sqlQT_CD


                    #region AddParameters
                    arrParametersQT_CD.Clear();
                    arrParametersQT_CD.Add(SqlHelper.CreateParameterObject("@Khoa", SqlDbType.NVarChar, ParameterDirection.Input, MyCommon.CurrentUserDauMoiID + "_" + dr["Khoa"]));
                    arrParametersQT_CD.Add(SqlHelper.CreateParameterObject("@DauMoiID", SqlDbType.Int, ParameterDirection.Input, MyCommon.CurrentUserDauMoiID));
                    arrParametersQT_CD.Add(SqlHelper.CreateParameterObject("@ID", SqlDbType.Int, ParameterDirection.Input, dr["ID"]));
                    arrParametersQT_CD.Add(SqlHelper.CreateParameterObject("@Ch_Truong", SqlDbType.Int, ParameterDirection.Input, dr["Ch_Truong"]));
                    arrParametersQT_CD.Add(SqlHelper.CreateParameterObject("@Bat_Dau", SqlDbType.DateTime, ParameterDirection.Input, Util.DATETIME.ToDateFromMMyyyy(dr["Bat_Dau"].ToString())));

                    arrParametersQT_CD.Add(SqlHelper.CreateParameterObject("@Ket_Thuc", SqlDbType.DateTime, ParameterDirection.Input, Util.DATETIME.ToDateFromMMyyyy(dr["Ket_Thuc"].ToString())));
                    arrParametersQT_CD.Add(SqlHelper.CreateParameterObject("@CVi_ChDau", SqlDbType.Int, ParameterDirection.Input, dr["CVi_ChDau"]));
                    arrParametersQT_CD.Add(SqlHelper.CreateParameterObject("@Don_Vi", SqlDbType.NVarChar, ParameterDirection.Input, Converter.TCVN3ToUnicode(dr["Don_Vi"].ToString())));
                    arrParametersQT_CD.Add(SqlHelper.CreateParameterObject("@UserID", SqlDbType.Int, ParameterDirection.Input, MyCommon.CurrentUserID));

                    #endregion AddParameters


                    SqlHelper.ExecuteNonQuery(CommandType.Text, sqlQT_CD, arrParametersQT_CD);

                    #endregion sqlQT_CD

                }

                #endregion QT_CD

                #region QT_CT

                DataTable dtQT_CT = SqlHelper_Convert.ExecuteDataTable(CommandType.Text, "Select * From QT_CT ");
                List<SqlParameter> arrParametersQT_CT = new List<SqlParameter>();

                string sqlQT_CT = "";

                #region SQLInsert
                sqlQT_CT = "Insert Into tblQT_CT(ID, Khoa, DauMoiID, Tu, Den, Chuc_T, Chuc, DonVi_T, DonVi, Cap_T, Cap, TG_Cap, Dang, TG_Dang, UserID, CreateDate) " +
                                "Values(@ID, @Khoa, @DauMoiID, @Tu, @Den, @Chuc_T, @Chuc, @DonVi_T, @DonVi, @Cap_T, @Cap, @TG_Cap, @Dang, @TG_Dang, @UserID, GetDate()) ";

                #endregion SQLInsert

                foreach (DataRow dr in dtQT_CT.Rows)
                {
                    lblTrangThai.Text = "Đang cập nhật QT_CT: " + dr["Khoa"].ToString();

                    Application.DoEvents();
                    //if (!CheckExitsCB(dr["Khoa"].ToString()))
                    //    continue;
                    #region sqlQT_CT


                    #region AddParameters
                    arrParametersQT_CT.Clear();
                    arrParametersQT_CT.Add(SqlHelper.CreateParameterObject("@Khoa", SqlDbType.NVarChar, ParameterDirection.Input, MyCommon.CurrentUserDauMoiID + "_" + dr["Khoa"]));
                    arrParametersQT_CT.Add(SqlHelper.CreateParameterObject("@DauMoiID", SqlDbType.Int, ParameterDirection.Input, MyCommon.CurrentUserDauMoiID));
                    arrParametersQT_CT.Add(SqlHelper.CreateParameterObject("@ID", SqlDbType.Int, ParameterDirection.Input, dr["ID"]));
                    arrParametersQT_CT.Add(SqlHelper.CreateParameterObject("@Tu", SqlDbType.DateTime, ParameterDirection.Input, Util.DATETIME.ToDateFromMMyyyy(dr["Tu"].ToString())));
                    arrParametersQT_CT.Add(SqlHelper.CreateParameterObject("@Den", SqlDbType.DateTime, ParameterDirection.Input, Util.DATETIME.ToDateFromMMyyyy(dr["Den"].ToString())));

                    arrParametersQT_CT.Add(SqlHelper.CreateParameterObject("@Chuc_T", SqlDbType.NVarChar, ParameterDirection.Input, Converter.TCVN3ToUnicode(dr["Chuc_T"].ToString())));
                    arrParametersQT_CT.Add(SqlHelper.CreateParameterObject("@Chuc", SqlDbType.Int, ParameterDirection.Input, dr["Chuc"]));
                    arrParametersQT_CT.Add(SqlHelper.CreateParameterObject("@DonVi_T", SqlDbType.NVarChar, ParameterDirection.Input, Converter.TCVN3ToUnicode(dr["DonVi_T"].ToString())));
                    arrParametersQT_CT.Add(SqlHelper.CreateParameterObject("@DonVi", SqlDbType.Int, ParameterDirection.Input, dr["DonVi"]));

                    arrParametersQT_CT.Add(SqlHelper.CreateParameterObject("@Cap_T", SqlDbType.NVarChar, ParameterDirection.Input, Converter.TCVN3ToUnicode(dr["Cap_T"].ToString())));
                    arrParametersQT_CT.Add(SqlHelper.CreateParameterObject("@Cap", SqlDbType.Int, ParameterDirection.Input, dr["Cap"]));
                    arrParametersQT_CT.Add(SqlHelper.CreateParameterObject("@TG_Cap", SqlDbType.DateTime, ParameterDirection.Input, Util.DATETIME.ToDateFromMMyyyy(dr["TG_Cap"].ToString())));
                    arrParametersQT_CT.Add(SqlHelper.CreateParameterObject("@Dang", SqlDbType.NVarChar, ParameterDirection.Input, Converter.TCVN3ToUnicode(dr["Dang"].ToString())));
                    arrParametersQT_CT.Add(SqlHelper.CreateParameterObject("@TG_Dang", SqlDbType.DateTime, ParameterDirection.Input, Util.DATETIME.ToDateFromMMyyyy(dr["TG_Dang"].ToString())));
                    arrParametersQT_CT.Add(SqlHelper.CreateParameterObject("@UserID", SqlDbType.Int, ParameterDirection.Input, MyCommon.CurrentUserID));

                    #endregion AddParameters


                    SqlHelper.ExecuteNonQuery(CommandType.Text, sqlQT_CT, arrParametersQT_CT);

                    #endregion sqlQT_CT

                }

                #endregion QT_CT

                #region QT_DG

                DataTable dtQT_DG = SqlHelper_Convert.ExecuteDataTable(CommandType.Text, "Select * From QT_DG ");
                List<SqlParameter> arrParametersQT_DG = new List<SqlParameter>();

                string sqlQT_DG = "";

                #region SQLInsert
                sqlQT_DG = "Insert Into tblQT_DG(ID, Khoa, DauMoiID, SKien_DGia, Thang_SK, NDung_SK, Ghi_Chu, UserID, CreateDate) " +
                                "Values(@ID, @Khoa, @DauMoiID, @SKien_DGia, @Thang_SK, @NDung_SK, @Ghi_Chu, @UserID, GetDate()) ";

                #endregion SQLInsert

                foreach (DataRow dr in dtQT_DG.Rows)
                {
                    lblTrangThai.Text = "Đang cập nhật QT_DG: " + dr["Khoa"].ToString();

                    Application.DoEvents();
                    //if (!CheckExitsCB(dr["Khoa"].ToString()))
                    //    continue;

                    #region sqlQT_DG


                    #region AddParameters
                    arrParametersQT_DG.Clear();
                    arrParametersQT_DG.Add(SqlHelper.CreateParameterObject("@Khoa", SqlDbType.NVarChar, ParameterDirection.Input, MyCommon.CurrentUserDauMoiID + "_" + dr["Khoa"]));
                    arrParametersQT_DG.Add(SqlHelper.CreateParameterObject("@DauMoiID", SqlDbType.Int, ParameterDirection.Input, MyCommon.CurrentUserDauMoiID));
                    arrParametersQT_DG.Add(SqlHelper.CreateParameterObject("@ID", SqlDbType.Int, ParameterDirection.Input, dr["ID"]));

                    arrParametersQT_DG.Add(SqlHelper.CreateParameterObject("@SKien_DGia", SqlDbType.Int, ParameterDirection.Input, dr["SKien_DGia"]));
                    arrParametersQT_DG.Add(SqlHelper.CreateParameterObject("@Thang_SK", SqlDbType.DateTime, ParameterDirection.Input, Util.DATETIME.ToDateFromMMyyyy(dr["Thang_SK"].ToString())));
                    arrParametersQT_DG.Add(SqlHelper.CreateParameterObject("@NDung_SK", SqlDbType.NVarChar, ParameterDirection.Input, Converter.TCVN3ToUnicode(dr["NDung_SK"].ToString())));
                    arrParametersQT_DG.Add(SqlHelper.CreateParameterObject("@Ghi_Chu", SqlDbType.NVarChar, ParameterDirection.Input, Converter.TCVN3ToUnicode(dr["Ghi_Chu"].ToString())));
                    arrParametersQT_DG.Add(SqlHelper.CreateParameterObject("@UserID", SqlDbType.Int, ParameterDirection.Input, MyCommon.CurrentUserID));

                    #endregion AddParameters


                    SqlHelper.ExecuteNonQuery(CommandType.Text, sqlQT_DG, arrParametersQT_DG);

                    #endregion sqlQT_DG

                }

                #endregion QT_DG

                #region QT_DT

                DataTable dtQT_DT = SqlHelper_Convert.ExecuteDataTable(CommandType.Text, "Select * From QT_DT ");
                List<SqlParameter> arrParametersQT_DT = new List<SqlParameter>();

                string sqlQT_DT = "";

                #region SQLInsert
                sqlQT_DT = "Insert Into tblQT_DT(ID, Khoa, DauMoiID, Loai_Hinh, Cap_Hoc, Ten_Nuoc, Ten_Co_So, CNganh_DT, Thang_BD, Thang_KT, Loai_TN_T, Bang_Cap, Luan_An, Dung_CNCT, UserID, CreateDate) " +
                                "Values(@ID, @Khoa, @DauMoiID, @Loai_Hinh, @Cap_Hoc, @Ten_Nuoc, @Ten_Co_So, @CNganh_DT, @Thang_BD, @Thang_KT, @Loai_TN_T, @Bang_Cap, @Luan_An, @Dung_CNCT, @UserID, GetDate()) ";

                #endregion SQLInsert

                foreach (DataRow dr in dtQT_DT.Rows)
                {
                    lblTrangThai.Text = "Đang cập nhật QT_DT: " + dr["Khoa"].ToString();

                    Application.DoEvents();
                    //if (!CheckExitsCB(dr["Khoa"].ToString()))
                    //    continue;
                    #region sqlQT_DT


                    #region AddParameters
                    arrParametersQT_DT.Clear();
                    arrParametersQT_DT.Add(SqlHelper.CreateParameterObject("@Khoa", SqlDbType.NVarChar, ParameterDirection.Input, MyCommon.CurrentUserDauMoiID + "_" + dr["Khoa"]));
                    arrParametersQT_DT.Add(SqlHelper.CreateParameterObject("@DauMoiID", SqlDbType.Int, ParameterDirection.Input, MyCommon.CurrentUserDauMoiID));
                    arrParametersQT_DT.Add(SqlHelper.CreateParameterObject("@ID", SqlDbType.Int, ParameterDirection.Input, dr["ID"]));

                    arrParametersQT_DT.Add(SqlHelper.CreateParameterObject("@Loai_Hinh", SqlDbType.Int, ParameterDirection.Input, dr["Loai_Hinh"]));
                    arrParametersQT_DT.Add(SqlHelper.CreateParameterObject("@Cap_Hoc", SqlDbType.Int, ParameterDirection.Input, dr["Cap_Hoc"]));
                    arrParametersQT_DT.Add(SqlHelper.CreateParameterObject("@Ten_Nuoc", SqlDbType.Int, ParameterDirection.Input, dr["Ten_Nuoc"]));
                    arrParametersQT_DT.Add(SqlHelper.CreateParameterObject("@Ten_Co_So", SqlDbType.Int, ParameterDirection.Input, dr["Ten_Co_So"]));
                    arrParametersQT_DT.Add(SqlHelper.CreateParameterObject("@CNganh_DT", SqlDbType.Int, ParameterDirection.Input, dr["CNganh_DT"]));
                    arrParametersQT_DT.Add(SqlHelper.CreateParameterObject("@Thang_BD", SqlDbType.DateTime, ParameterDirection.Input, Util.DATETIME.ToDateFromMMyyyy(dr["Thang_BD"].ToString())));
                    arrParametersQT_DT.Add(SqlHelper.CreateParameterObject("@Thang_KT", SqlDbType.DateTime, ParameterDirection.Input, Util.DATETIME.ToDateFromMMyyyy(dr["Thang_KT"].ToString())));
                    arrParametersQT_DT.Add(SqlHelper.CreateParameterObject("@Loai_TN_T", SqlDbType.NVarChar, ParameterDirection.Input, Converter.TCVN3ToUnicode(dr["Loai_TN_T"].ToString())));
                    arrParametersQT_DT.Add(SqlHelper.CreateParameterObject("@Bang_Cap", SqlDbType.NVarChar, ParameterDirection.Input, Converter.TCVN3ToUnicode(dr["Bang_Cap"].ToString())));
                    arrParametersQT_DT.Add(SqlHelper.CreateParameterObject("@Luan_An", SqlDbType.NVarChar, ParameterDirection.Input, Converter.TCVN3ToUnicode(dr["Luan_An"].ToString())));
                    arrParametersQT_DT.Add(SqlHelper.CreateParameterObject("@Dung_CNCT", SqlDbType.Bit, ParameterDirection.Input, 0));
                    arrParametersQT_DT.Add(SqlHelper.CreateParameterObject("@UserID", SqlDbType.Int, ParameterDirection.Input, MyCommon.CurrentUserID));

                    #endregion AddParameters


                    SqlHelper.ExecuteNonQuery(CommandType.Text, sqlQT_DT, arrParametersQT_DT);

                    #endregion sqlQT_DT

                }

                #endregion QT_DT



                #region Tieng

                DataTable dtTieng = SqlHelper_Convert.ExecuteDataTable(CommandType.Text, "Select * From Tieng ");
                List<SqlParameter> arrParametersTieng = new List<SqlParameter>();

                string sqlTieng = "";

                #region SQLInsert
                sqlTieng = "Insert Into tblTieng(ID, Khoa, DauMoiID, Loai, NgonNgu_T, Ma_NNgu, Ma_DToc, TrinhDo, ThoiGian, UserID, CreateDate) " +
                                "Values(@ID, @Khoa, @DauMoiID, @Loai, @NgonNgu_T, @Ma_NNgu, @Ma_DToc, @TrinhDo, @ThoiGian, @UserID, GetDate()); ";

                #endregion SQLInsert

                foreach (DataRow dr in dtTieng.Rows)
                {
                    lblTrangThai.Text = "Đang cập nhật Tieng: " + dr["Khoa"].ToString();

                    Application.DoEvents();
                    //if (!CheckExitsCB(dr["Khoa"].ToString()))
                    //    continue;

                    #region sqlTieng


                    #region AddParameters
                    arrParametersTieng.Clear();
                    arrParametersTieng.Add(SqlHelper.CreateParameterObject("@Khoa", SqlDbType.NVarChar, ParameterDirection.Input, MyCommon.CurrentUserDauMoiID + "_" + dr["Khoa"]));
                    arrParametersTieng.Add(SqlHelper.CreateParameterObject("@DauMoiID", SqlDbType.Int, ParameterDirection.Input, MyCommon.CurrentUserDauMoiID));
                    arrParametersTieng.Add(SqlHelper.CreateParameterObject("@ID", SqlDbType.Int, ParameterDirection.Input, dr["ID"]));
                    arrParametersTieng.Add(SqlHelper.CreateParameterObject("@Loai", SqlDbType.Int, ParameterDirection.Input, dr["Loai"]));
                    arrParametersTieng.Add(SqlHelper.CreateParameterObject("@NgonNgu_T", SqlDbType.NVarChar, ParameterDirection.Input, Converter.TCVN3ToUnicode(dr["NgonNgu_T"].ToString())));
                    if (dr["Loai"].ToString() == "1")
                    {
                        arrParametersTieng.Add(SqlHelper.CreateParameterObject("@Ma_NNgu", SqlDbType.Int, ParameterDirection.Input, dr["Ma_NNgu"]));
                        arrParametersTieng.Add(SqlHelper.CreateParameterObject("@Ma_DToc", SqlDbType.Int, ParameterDirection.Input, null));
                    }
                    else
                    {
                        arrParametersTieng.Add(SqlHelper.CreateParameterObject("@Ma_NNgu", SqlDbType.Int, ParameterDirection.Input, null));
                        arrParametersTieng.Add(SqlHelper.CreateParameterObject("@Ma_DToc", SqlDbType.Int, ParameterDirection.Input, dr["Ma_DToc"]));
                    }
                    arrParametersTieng.Add(SqlHelper.CreateParameterObject("@TrinhDo", SqlDbType.NVarChar, ParameterDirection.Input, Converter.TCVN3ToUnicode(dr["TrinhDo"].ToString())));
                    arrParametersTieng.Add(SqlHelper.CreateParameterObject("@ThoiGian", SqlDbType.DateTime, ParameterDirection.Input, Util.DATETIME.ToDateFromMMyyyy(dr["ThoiGian"].ToString())));
                    arrParametersTieng.Add(SqlHelper.CreateParameterObject("@UserID", SqlDbType.Int, ParameterDirection.Input, MyCommon.CurrentUserID));

                    #endregion AddParameters


                    SqlHelper.ExecuteNonQuery(CommandType.Text, sqlTieng, arrParametersTieng);

                    #endregion sqlTieng

                }

                #endregion Tieng

                #region ThanNhan

                DataTable dtThanNhan = SqlHelper_Convert.ExecuteDataTable(CommandType.Text, "Select * From ThanNhan ");
                List<SqlParameter> arrParametersThanNhan = new List<SqlParameter>();

                string sqlThanNhan = "";

                #region SQLInsert
                sqlThanNhan = "Insert Into tblThanNhan(ID, Khoa, DauMoiID, Ten_TNhan, Nam_Sinh, Quan_He, DDiem_CT_T, DDiem_KT_T, Nghe, Dia_Chi, Ghi_Chu, UserID, CreateDate) " +
                                "Values(@ID, @Khoa, @DauMoiID, @Ten_TNhan, @Nam_Sinh, @Quan_He, @DDiem_CT_T, @DDiem_KT_T, @Nghe, @Dia_Chi, @Ghi_Chu, @UserID, GetDate()) ";

                #endregion SQLInsert

                foreach (DataRow dr in dtThanNhan.Rows)
                {
                    try
                    {
                        lblTrangThai.Text = "Đang cập nhật ThanhNhan: " + dr["Khoa"].ToString();

                        Application.DoEvents();
                        //if (!CheckExitsCB(dr["Khoa"].ToString()))
                        //    continue;

                        #region sqlThanNhan


                        #region AddParameters
                        arrParametersThanNhan.Clear();
                        arrParametersThanNhan.Add(SqlHelper.CreateParameterObject("@Khoa", SqlDbType.NVarChar, ParameterDirection.Input, MyCommon.CurrentUserDauMoiID + "_" + dr["Khoa"]));
                        arrParametersThanNhan.Add(SqlHelper.CreateParameterObject("@DauMoiID", SqlDbType.Int, ParameterDirection.Input, MyCommon.CurrentUserDauMoiID));

                        arrParametersThanNhan.Add(SqlHelper.CreateParameterObject("@ID", SqlDbType.Int, ParameterDirection.Input, dr["ID"]));

                        arrParametersThanNhan.Add(SqlHelper.CreateParameterObject("@Ten_TNhan", SqlDbType.NVarChar, ParameterDirection.Input, Converter.TCVN3ToUnicode(dr["Ten_TNhan"].ToString())));
                        arrParametersThanNhan.Add(SqlHelper.CreateParameterObject("@Nam_Sinh", SqlDbType.NVarChar, ParameterDirection.Input, dr["Nam_Sinh"]));
                        arrParametersThanNhan.Add(SqlHelper.CreateParameterObject("@Quan_He", SqlDbType.Int, ParameterDirection.Input, dr["Quan_He"]));
                        arrParametersThanNhan.Add(SqlHelper.CreateParameterObject("@DDiem_CT_T", SqlDbType.NVarChar, ParameterDirection.Input, Converter.TCVN3ToUnicode(dr["DDiem_CT_T"].ToString())));
                        arrParametersThanNhan.Add(SqlHelper.CreateParameterObject("@DDiem_KT_T", SqlDbType.NVarChar, ParameterDirection.Input, Converter.TCVN3ToUnicode(dr["DDiem_KT_T"].ToString())));
                        arrParametersThanNhan.Add(SqlHelper.CreateParameterObject("@Nghe", SqlDbType.NVarChar, ParameterDirection.Input, Converter.TCVN3ToUnicode(dr["Nghe"].ToString())));
                        arrParametersThanNhan.Add(SqlHelper.CreateParameterObject("@Dia_Chi", SqlDbType.NVarChar, ParameterDirection.Input, Converter.TCVN3ToUnicode(dr["Dia_Chi"].ToString())));
                        arrParametersThanNhan.Add(SqlHelper.CreateParameterObject("@Ghi_Chu", SqlDbType.NVarChar, ParameterDirection.Input, Converter.TCVN3ToUnicode(dr["Ghi_Chu"].ToString())));
                        arrParametersThanNhan.Add(SqlHelper.CreateParameterObject("@UserID", SqlDbType.Int, ParameterDirection.Input, MyCommon.CurrentUserID));

                        #endregion AddParameters


                        SqlHelper.ExecuteNonQuery(CommandType.Text, sqlThanNhan, arrParametersThanNhan);

                        #endregion sqlThanNhan
                    }
                    catch { }

                }

                #endregion ThanNhan
                lblTrangThai.Text = "Thực hiện xong";
                MyCommon.ShowMessage("thực hiện xong");
            }
            catch (Exception _ex)
            {
                MyCommon.ShowDialogMessage(_ex);
            }
        }
    }
}
//#region QT_CT

//               DataTable dtQT_CT = SqlHelper_Convert.ExecuteDataTable(CommandType.Text, "Select * From QT_CT ");
//               List<SqlParameter> arrParametersQT_CT = new List<SqlParameter>();

//               string sqlQT_CT = "";

//               #region SQLInsert
//               sqlQT_CT = "Insert Into tblQT_CT(ID, Khoa, DauMoiID, Tu, Den, Chuc_T, Chuc, DonVi_T, DonVi, Cap_T, Cap, TG_Cap, Dang, TG_Dang, UserID, CreateDate) " +
//                               "Values(@ID, @Khoa, @DauMoiID, @Tu, @Den, @Chuc_T, @Chuc, @DonVi_T, @DonVi, @Cap_T, @Cap, @TG_Cap, @Dang, @TG_Dang, @UserID, GetDate()) ";

//               #endregion SQLInsert

//               foreach (DataRow dr in dtQT_CT.Rows)
//               {
//                   lblTrangThai.Text = "Đang cập nhật QT_CT: " + dr["Khoa"].ToString();

//                   Application.DoEvents();
//                   if (!CheckExitsCB(dr["Khoa"].ToString()))
//                       continue;
//                   #region sqlQT_CT


//                   #region AddParameters
//                   arrParametersQT_CT.Clear();
//                   arrParametersQT_CT.Add(SqlHelper.CreateParameterObject("@Khoa", SqlDbType.NVarChar, ParameterDirection.Input, MyCommon.CurrentUserDauMoiID + "_" + dr["Khoa"]));
//                   arrParametersQT_CT.Add(SqlHelper.CreateParameterObject("@DauMoiID", SqlDbType.Int, ParameterDirection.Input, MyCommon.CurrentUserDauMoiID));
//                   arrParametersQT_CT.Add(SqlHelper.CreateParameterObject("@ID", SqlDbType.Int, ParameterDirection.Input, dr["ID"]));
//                   arrParametersQT_CT.Add(SqlHelper.CreateParameterObject("@Tu", SqlDbType.DateTime, ParameterDirection.Input, Util.DATETIME.ToDateFromMMyyyy(dr["Tu"].ToString())));
//                   arrParametersQT_CT.Add(SqlHelper.CreateParameterObject("@Den", SqlDbType.DateTime, ParameterDirection.Input, Util.DATETIME.ToDateFromMMyyyy(dr["Den"].ToString())));

//                   arrParametersQT_CT.Add(SqlHelper.CreateParameterObject("@Chuc_T", SqlDbType.NVarChar, ParameterDirection.Input, Converter.TCVN3ToUnicode(dr["Chuc_T"].ToString())));
//                   arrParametersQT_CT.Add(SqlHelper.CreateParameterObject("@Chuc", SqlDbType.Int, ParameterDirection.Input, dr["Chuc"]));
//                   arrParametersQT_CT.Add(SqlHelper.CreateParameterObject("@DonVi_T", SqlDbType.NVarChar, ParameterDirection.Input, Converter.TCVN3ToUnicode(dr["DonVi_T"].ToString())));
//                   arrParametersQT_CT.Add(SqlHelper.CreateParameterObject("@DonVi", SqlDbType.Int, ParameterDirection.Input, dr["DonVi"]));

//                   arrParametersQT_CT.Add(SqlHelper.CreateParameterObject("@Cap_T", SqlDbType.NVarChar, ParameterDirection.Input, Converter.TCVN3ToUnicode(dr["Cap_T"].ToString())));
//                   arrParametersQT_CT.Add(SqlHelper.CreateParameterObject("@Cap", SqlDbType.Int, ParameterDirection.Input, dr["Cap"]));
//                   arrParametersQT_CT.Add(SqlHelper.CreateParameterObject("@TG_Cap", SqlDbType.DateTime, ParameterDirection.Input, Util.DATETIME.ToDateFromMMyyyy(dr["TG_Cap"].ToString())));
//                   arrParametersQT_CT.Add(SqlHelper.CreateParameterObject("@Dang", SqlDbType.NVarChar, ParameterDirection.Input, Converter.TCVN3ToUnicode(dr["Dang"].ToString())));
//                   arrParametersQT_CT.Add(SqlHelper.CreateParameterObject("@TG_Dang", SqlDbType.DateTime, ParameterDirection.Input, Util.DATETIME.ToDateFromMMyyyy(dr["TG_Dang"].ToString())));
//                   arrParametersQT_CT.Add(SqlHelper.CreateParameterObject("@UserID", SqlDbType.Int, ParameterDirection.Input, MyCommon.CurrentUserID));

//                   #endregion AddParameters


//                   SqlHelper.ExecuteNonQuery(CommandType.Text, sqlQT_CT, arrParametersQT_CT);

//                   #endregion sqlQT_CT

//               }

//               #endregion QT_CT